Skip to content

Files

Latest commit

 

History

History
35 lines (22 loc) · 945 Bytes

SC1082.md

File metadata and controls

35 lines (22 loc) · 945 Bytes

Pattern: Use of UTF-8 BOM for shell script

Issue: -

Description

Some editors may save a file with a Byte Order Mark to mark the file as UTF-8. Shells do not understand this and will give errors on the first line:

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

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

To fix it, remove the byte order mark. One way of doing this is LC_CTYPE=C sed '1s/^...//' < yourscript.

Example of incorrect 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"

Example of correct code:

The code is correct when this garbage does not appear.

Further Reading