I am new to Linux, and I have a shell script (.sh) file I on my Desktop that I want to run.
This is the content of the test.sh file on my Desktop directory:
#!bin/bash
#test.sh
echo "test"I want to run (execute) test.sh through the terminal. These are the commands that I'm using:
cd DesktopI give permission to run test.sh with:
chmod +x test.shand then try to open the file:
test.shBut I get this error:
test.sh: command not foundand when I enter test.sh with ./, I again get this error:
bash: ./test.sh: bin/bash: bad interpreter: No such file or directoryWhat am I doing wrong?
3 Answers
bash: ./test.sh: bin/bash: bad interpreter: No such file or directory
Replace:
#!bin/bashWith:
#!/bin/bashbin/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 $PATHIf 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/bashThat is the binary that will interpret and run your script.
To run a bash script, do the following
./scriptname.shIn your example:
./test.shin the directory where you have the script.
0I edited the .sh file on a Windows machine and saw similar issue. The issue was fixed after running dos2unix on the script.