Shell logoShell/
SH-1082

File has UTF-8 BOMSH-1082

Critical severityCritical
Bug Risk categoryBug Risk

Some editors may save a file with a Byte Order Mark to mark the file as UTF-8.

Problematic code:

This is an encoding error that can't be seen in the script itself, but cat -v will show three bytes of garbage at the start of the file.

$ cat -v file
M-oM-;M-?#!/bin/bash
echo "hello world"

Shells do not understand this and will emit errors on the first line:

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

$ dash myscript
myscript: 1: myscript: #!/bin/sh: not found

To fix it, remove the byte order mark. One way of doing this is LC_CTYPE=C sed '1s/^...//' < yourscript. Verify that the BOM is gone with cat -v.