Question

In the following script (saved as script.sh):

#!/bin/sh
cd $MY_PYTHON_WORKING_DIRECTORY
python script1.py
python script2.py

Then, when I try to run the command script.sh in my bash shell, I got the error bash: script.sh: command not found. Why does this not work as expected? If the first line of any scripts start by #! prefix, then the following path on the line is interpreted as a command, right? For your information, even if I changed my first line to #!/bin/bash, the same error still occurred. If I run the script as either sh script.sh or bash script.sh, then the script ran as expected.

Is there any way to run the script by just hitting script.sh?

One more question, between sh and bash, which should I use? I'm on OS X 10.8 and my default shell is currently set bash, but I wonder which one to use going forward.

Thanks.

Was it helpful?

Solution

First, make the script executable:

chmod u+x script.sh

Second, your current directory is not in your $PATH. Therefore, you have to run the script with a path (relative is enough):

./script.sh
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top