This question already has an answer here:

I don't understand why I've got this error:

line 1: #!/bin/bash: No such file or directory

while running any piece of bash script like this:

echo "pouet"

I've tried running it on a Fedora 19 and everything went well.

I'm on Debian 7, I've tried parsing the first line to search for \n\r but everything was clean (every script I've made so far seems to behave the same way).

My $PATH looks like this: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. I've tried it with a normal user or root, same result. But the rest of the script seems to behave normally (echo is interpreted). And yes, /bin/bash exists and is executable.


$ LC_ALL=C sed -n l < tesT.sh
echo "pouet"$

marked as duplicate by michas, Anthon, rahmu, slm, Zelda Jan 18 '14 at 15:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What does LC_ALL=C sed -n l < your-script give? – Stéphane Chazelas Jan 18 '14 at 8:11
  • it gives me somthing like this : LC_ALL=C sed -n l < tesT.sh \357\273\277#!/bin/bash$ echo "pouet"$ – doctori Jan 18 '14 at 8:15
  • please add the output of head -1 yourscript | od -c – michas Jan 18 '14 at 8:18
  • 1
    @Stephane Chazelas: According to that question the error message is the same. Also the solution presented there is exactly the right one in this case. – michas Jan 18 '14 at 8:28
  • 1
    @michas, I agree the questions are probably the same (though the error messages differ), but the accepted answer there, though giving the right approach to investigate the problem, is not giving the right explanation for the problem. Here, and there, it's not a CRLF issue. – Stéphane Chazelas Jan 18 '14 at 9:04

See #!/bin/bash - no such file or directory.

Something is wrong with the first line of your script.


head -n 1 yourscript | LC_ALL=C od -tc


LC_ALL=C sed -n 'l;q' your-script

to find out, what is wrong.

If the output starts with 357 273 277 it is an UTF8 byte order mark. In vim you can use set nobomb to remove it.

Neither the kernel (which interprets the she-bang line), nor your system's sh (which is invoked for scripts that don't have a she-bang) recognise that BOM, so what you're seeing here is:

  1. The kernel returns ENOEXEC upon executing that script as it's not a recognised executable (it's not a native binary executable, and it's not a script as it doesn't start with #!).
  2. Your interactive shell, upon that ENOEXEC, calls sh on it.
  3. That sh reads and interprets the file. The first line is not a comment, the # is not preceded by a blank, so it does try to execute <BOM>#/bin/bash, and reports an error message.
  • just consolidating all those comments into a real answer. – michas Jan 18 '14 at 8:52
  • there are three invisible characters at the beginning of the file called BOM. You can see them in any hex viewer. There are many easy ways how to remove them: unix.stackexchange.com/questions/381230/… – xerostomus May 26 '18 at 8:16

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