I am very, very new to UNIX programming (running on MacOSX Mountain Lion via Terminal). I\'ve been learning the basics from a bioinformatics and molecular methods course (we
Make sure you are not using "PATH" as a variable, which will override the existing PATH for environment variables.
Also make sure /bin/bash is the proper location for bash .... if you took that line from an example somewhere it may not match your particular server. If you are specifying an invalid location for bash you're going to have a problem.
#! /bin/bash
^---
remove the indicated space. The shebang should be
#!/bin/bash
Also try to dos2unix
the shell script, because sometimes it has Windows line endings and the shell does not recognize it.
$ dos2unix MigrateNshell.sh
This helps sometimes.
First:
chmod 777 ./MigrateNshell.sh
Then:
./MigrateNshell.sh
Or, add your program to a directory recognized in your $PATH variable. Example: Path Variable Example
Which will then allow you to call your program without ./
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.