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
Try chmod u+x MigrateNshell.sh
For security reasons, the shell will not search the current directory (by default) for an executable. You have to be specific, and tell bash
that your script is in the current directory (.
):
$ ./MigrateNshell.sh
There have been a few good comments about adding the shebang line to the beginning of the script. I'd like to add a recommendation to use the env command as well, for additional portability.
While #!/bin/bash
may be the correct location on your system, that's not universal. Additionally, that may not be the user's preferred bash. #!/usr/bin/env bash
will select the first bash found in the path.
Add below lines in your .profile path
PATH=$PATH:$HOME/bin:$Dir_where_script_exists
export PATH
Now your script should work without ./
Raj Dagla
I'm new to shell scripting too, but I had this same issue. Make sure at the end of your script you have a blank line. Otherwise it won't work.
Change the first line to the following as pointed out by Marc B
#!/bin/bash
Then mark the script as executable and execute it from the command line
chmod +x MigrateNshell.sh
./MigrateNshell.sh
or simply execute bash from the command line passing in your script as a parameter
/bin/bash MigrateNshell.sh