Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanted to execute a shell script:

-rwxr-x--x 1 root root   17234 Jun  6 18:31

I tried to do a standard procedure, but I am got this error:

localhost 389 -l /opt/fews/sessions/AMGWM19/log/2013-06-06-143637_CLA-0 
DEBUG   cd/etc/opt/ldapfiles/ldif_in ;
localhost 389 -l /opt/fews/sessions/AMGWM19/log/2013-06-06-143637_CLA-0
**ERROR  sh: ./ /bin/bash^M: bad interpreter: No such file or directory**

What does it mean? I was doing this as the root user under the root group.

Does it mean that the file does not have the correct permission for the root user?

share|improve this question

This isn't a permission issue, you aren't getting a message about permissions

/bin/bash^M: bad interpreter: No such file or directory

The script indicates that it must be executed by a shell located at /bin/bash^M. There is no such file: it's called /bin/bash.

The ^M is a carriage return character. Linux uses the line feed character to mark the end of a line, whereas Windows uses the two-character sequence CR LF. Your file has Windows line endings, which is confusing Linux.

Remove the spurious CR characters. You can do it with the following command:

sed -i -e 's/\r$//'
share|improve this answer
Or install and use the dos2unix program. – argentpepper Jun 6 '13 at 22:56
thank you for this, all other answers Ive found so far have not helped. This one did it! – qodeninja Jun 9 '14 at 23:39

In vim you could also use :set ff=unix and then save the file, or :set ff=dos to get DOS formatting again.

share|improve this answer
this one did it for me, thx – bunkerdive Aug 6 '15 at 19:53

/bin/bash^M: bad interpreter: No such file or directory The ^M is a special character so somewhere you have extra characters around.

You need to find and remove wherever the ^M is. I believe it's in the first line of the script but without the script's source I can't tell you whether that's the case or not.

share|improve this answer
Actually, you can conclude from the error message that the ^M is on the first line. And it's not just any special character, it's the first part of a Windows newline sequence. – Gilles Jun 6 '13 at 20:28
eww windows. you should not be writing bash scripts from windows! – Thomas Ward Jun 6 '13 at 20:50

As explained in the other answers, this is a format issue. So, the answer is to change the format from DOS to Unix style line endings. This is yet another simple way to fix your file 'in place'

$ fromdos file

It's available in package tofordos:

$ sudo apt-get install tofrodos

share|improve this answer

Do vi <your script>.

then :set list; it will display any of the special characters in your script.

then replace the character:

:%s/^M//gc [to type ^M press Ctrl + v + m]

share|improve this answer

You can also use gedit to remove the unwanted characters. Under the File menu select Save As and set the line end type unix/Linux.

share|improve this answer
+1 for this because it helped me with MacOS line endings. – Bobble Apr 3 '14 at 11:52

The Problem ist you edit with Dos!

open your file with vi then set unix with:

:set ff=unix

and it all fine

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.