#!/bin/sh - does not help

Hi,

I am using bash shell and have a simple shell script (test.sh) as given below,

#!/bin/sh
echo "testing..."

Here, when I execute the script like below, it works well.

cmd -> sh test.sh
testing...

I have seen, these files can be executed, simply by using the file name directly, like given below. But, in my case it gives "command not found" error.

cmd -> test.sh
-bash: test.sh: command not found

In the first line of the script, I have given as "#!/bin/sh", hence to my knowledge, it should run with prefix /bin/sh command automatically and invoke as given below,

/bin/sh test.sh

Alternatively, in the first line, I also tried using "#!/bin/bash", still get the same error. What is the mistake I am making, please help, thank you.

The directory from which you are running the script must be #included in PATH ,
moreover you have to enable the executable bit on the script .

chmod u+x test.sh

Regards ,
CodeManiac

The directory from which you are running the script must be #included in PATH ,
moreover you have to enable the executable bit on the script .

chmod u+x test.sh

Regards ,
CodeManiac

In additon to the above advice about $PATH and providing that the script file has execute permissions,you should be able to execute it as:

./test.sh
# Or
/full_path_to_script/test.sh