1

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.

4

1 回答 1

6

首先,使脚本可执行:

chmod u+x script.sh

其次,您的当前目录不在您的 $PATH 中。因此,您必须使用路径运行脚本(相对就足够了):

./script.sh
于 2013-05-29T10:32:21.833 回答