Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script: bad interpreter

Question: I get this error message:

export: bad interpreter: No such file or directory

when I execute this bash script:

#!/bin/bash MONO_PREFIX=/opt/mono-2.6 GNOME_PREFIX=/opt/gnome-2.6 export DYLD_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_PATH export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig PATH=$MONO_PREFIX/bin:$PATH PS1="[mono-2.6] \w @ " 

But the bash path seems to be correct:

asshat@IS1300:~/sources/mono-2.6# which bash /bin/bash  asshat@IS1300:~# cd sources/ asshat@IS1300:~/sources# cd mono-2.6/ asshat@IS1300:~/sources/mono-2.6# ./mono-2.6-environment export: bad interpreter: No such file or directory asshat@IS1300:~/sources/mono-2.6# ls download  mono-2.4  mono-2.4-environment  mono-2.6  mono-2.6-environment asshat@IS1300:~/sources/mono-2.6# cp mono-2.6-environment mono-2.6-environment.sh asshat@IS1300:~/sources/mono-2.6# ./mono-2.6-environment.sh export: bad interpreter: No such file or directory asshat@IS1300:~/sources/mono-2.6# ls download  mono-2.4-environment  mono-2.6-environment mono-2.4  mono-2.6              mono-2.6-environment.sh asshat@IS1300:~/sources/mono-2.6# bash mono-2.6-environment asshat@IS1300:~/sources/mono-2.6# 

What am I doing wrong? Or is this a Lucid Lynx bug?

I did chmod + x

like image 666
Stefan Steiger Avatar asked May 15 '10 20:05

Stefan Steiger


People also ask

How do I fix bin bash'm a bad interpreter?

To fix the error in the Windows operating system, open the bash script file in the Notepad++ editor and then go to the preferences tab via the settings menu as below. Close the window after choosing Unix/OSX as the format. Afterwards, save and close the file.

What is bad interpreter?

/bin/bash^M: bad interpreter: No such file or directory ^M is a character used by Windows to mark the end of a line (so it is a carriage return) and that matches the CR character.

What does #$ mean in bash?

#$ does "nothing", as # is starting comment and everything behind it on the same line is ignored (with the notable exception of the "shebang"). $# prints the number of arguments passed to a shell script (like $* prints all arguments). Follow this answer to receive notifications. edited Jul 9 at 13:55.

What is interpreter in bash?

The bash command interpreter. At the beginning of its execution the program interpreter shows us the prompt and is ready to execute any command or program in the current directory. This leads us to answer the first three questions about this program.


1 Answers

The first line, #!/bin/bash, tells Linux where to find the interpreter. The script should also be executable with chmod +x script.sh, which it appears you did.

It is highly likely that you created this file with a windows editor, which will place a <cr><lf> at the end of each line. This is the standard under dos / windows. OS X will place a <cr> at the end of each line. However, under Unix / Linux, the standard is to just put a <lf> at the end of the line.

Linux is now looking for a file called /bin/bash<cr> to interpret the file, where <cr> is a carriage return character, which is a valid file character under Linux. Such a file doesn't exist. Hence the error.

Solution: Edit the file with an editor on Linux and get rid of the extra <cr>. One tool that usually works when the file is edited on Windows is dos2unix.

like image 143
Matthias Wandel Avatar answered Sep 19 '22 17:09

Matthias Wandel