this script makes a symbolic link in your /usr/bin directory
that way you don't have to keep moving files or adding many directories
that have different scripts to your PATH statement
Code:
#!/bin/bash
# Author: Joshua Bailey
# Script: link2path
# Summary: makes a symbolic link to a specified file in your /usr/bin dir.
# Syntax: link2path /pathtofile/filename
# Syntax2: link2path /pathtofile/filename /path/to/place/link/
function notAForwardSlash
{
if [[ $1 != '/' ]]
then
return 0
else
return 1
fi
}
function getFileName
{
STRING=$1
LENGTH=${#STRING}
n=0
for ((n=0;n <= $LENGTH; n++))
do
CHAR=${STRING:$n:1}
if notAForwardSlash $CHAR
then
FileName=$FileName$CHAR
else
FileName=""
fi
done
}
FILE=$1
cur_dir=$PWD
getFileName $FILE
if [[ ${FILE:0:1} != '/' ]]
then
FILE=$cur_dir/$FILE
fi
if [[ ! $# = 2 ]]
then
cd /usr/bin
else
if [[ -d $2 ]]
then
cd $2
# new option to add specified directory to $PATH
# if it's not in $PATH already
if [[ ! `echo $PATH | grep $2` ]]
then
echo "$2 is not in your path statement"
read -p "Would you like it to be? (y/n) " ans
ans=`echo $ans | tr :upper: :lower:`
ans=${ans:0:1}
if [[ $ans -eq "y" ]]
then
echo "PATH=$PATH:$2" >> ~/.bashrc
PATH=$PATH:$2
else
echo "Error: $2 not in path statement"
exit
fi
fi # end new option
else
echo "Error: $2 doesn't exist!"
exit
fi
fi
ln -s $FILE $FileName
cd $cur_dir
it's a little handy...like most scripts
it's an easy reference for some not-so-easy commands
:edit: added ability to choose which directory you wish to place it in
:edit: added ability to add directory specified to PATH statement