문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top