#!/bin/bash # Author: Joshua Bailey # Script: link2path # Summary: makes a symbolic link to a specified file in your /usr/bin dir. # Syntax1: link2path '/pathtofile/filename' # Syntax2: link2path '/pathtofile/filename' '/dir/toadd/linkto' 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 } echo $PATH | grep $2 > /dev/null if [[ $? != 0 ]] 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 == 'y' ]] then newpath=`grep 'PATH=' ~/.bashrc` if [[ ${#newpath} == 0 ]] then newpath=`echo PATH=$PATH` fi if [[ ${#newpath} == 5 ]] then newpath=`echo PATH=$PATH` fi echo $newpath bob=`echo $newpath:$2` PATH=$PATH:$2 grep -v 'PATH=' ~/.bashrc > ~/.tmprc echo $bob >> ~/.tmprc mv ~/.bashrc ~/tmp mv ~/.tmprc ~/.bashrc rm ~/tmp else exit fi fi FILE=$1 cur_dir=`pwd` getFileName $FILE if [[ ${FILE:0:1} != '/' ]] then FILE=$cur_dir/$FILE fi cd $2 ln -s $FILE $FileName cd $cur_dir