john400
john400

Reputation: 402

Running a Bash script results in 'Bad interpreter: No such file or directory' error

I did found questions on

Bad interpreter: No such file or directory thing on SO.

My issue is also solved when I changed the script from

#!/usr/bin/bash
echo -e "\t\t\e[92mHello from the Test Script!\e[39m"

to:

#!/bin/bash
echo -e "\t\t\e[92mHello from the Test Script!\e[39m"

after I did the first line change from looking an answer here.

Shell script: Bad interpreter.No such file or directory

I can not understand why removing the /usr from the first line helps.

P.S.I am learning about linux file permissions and I was unable to execute my file even after changing the permission using '755'. So, please if anyone can explain me this.Thanks in advance.:)

Upvotes: 1

Views: 21244

Answers (4)

HelpBox
HelpBox

Reputation: 51

You can also call your script by adding "./" at the beginning in case you call it from the local directory. The other solution is to call it by specifying its full path.

Upvotes: 0

SkorpEN
SkorpEN

Reputation: 2709

In my case adding sh before script name solved the issue.

Upvotes: 1

Burhan Khalid
Burhan Khalid

Reputation: 174622

On your system, the bash shell lives in /bin/bash and not /usr/bin/bash.

The path after the ! should be the path to an executable that will be passed the contents of the script as an argument.

You can read more about this at wikipedia

As for the second part of your question; it would not have mattered what the permissions are; as the file was pointing to a bad interpreter.

For more on unix file permissions, I suggest reading this entry on wikipedia.

Upvotes: 2

codeforester
codeforester

Reputation: 42999

That's because there is no bash binary at /usr/bin/bash and the correct path for bash is /bin/bash.

The #! line at the top of scripts, called the shebang, determines what program (sh, bash, ruby, perl, python, etc.) is used for running the script.

This post covers this topic well:

https://unix.stackexchange.com/questions/87560/does-the-shebang-determine-the-shell-which-runs-the-script

Upvotes: 1

Related Questions