Shell script file (.sh) does not run, and throws an error
bash: ./test.sh: bin/bash: bad interpreter: No such file or directory
Replace:
#!bin/bash
With:
#!/bin/bash
bin/bash
is a path relative to the current directory. /bin/bash
is an absolute path that works whatever the current directory is.
Also, have a look at your PATH:
echo $PATH
If you place test.sh
in any directory listed there and you will will be able to execute it without the ./
or other path specifier. Many people create a $HOME/bin
directory, place all their scripts there, and add it to their PATH.
To be able to run your bash script, change first line to
#!/bin/bash
That is the binary that will interpret and run your script.
To run a bash script, do the following
./scriptname.sh
In your example:
./test.sh
in the directory where you have the script.
I edited the .sh file on a Windows machine and saw similar issue. The issue was fixed after running dos2unix
on the script.