Unix has a variable called PATH
that is a list of directories where to find commands.
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/david/bin
If I type a command foo
at the command line, my shell will first see if there's an executable command /usr/local/bin/foo
. If there is, it will execute /usr/local/bin/foo
. If not, it will see if there's an executable command /usr/bin/foo
and if not there, it will look to see if /bin/foo
exists, etc. until it gets to /Users/david/bin/foo
.
If it can't find a command foo
in any of those directories, it tell me command not found.
There are several ways I can handle this issue:
bash foo
since foo
is a shell script./Users/david/foo
or $PWD/foo
or just plain ./foo
.$PATH
variable to add the directory that contains your commands to the PATH.You can modify $HOME/.bash_profile
or $HOME/.profile
if .bash_profile
doesn't exist. I did that to add in /usr/local/bin
which I placed first in my path. This way, I can override the standard commands that are in the OS. For example, I have Ant 1.9.1, but the Mac came with Ant 1.8.4. I put my ant
command in /usr/local/bin
, so my version of ant
will execute first. I also added $HOME/bin
to the end of the PATH for my own commands. If I had a file like the one you want to execute, I'll place it in $HOME/bin to execute it.