SLURM does not recognize job script

Problem

Upon job submit Slurm refuses to recognize your job script as a valid batch script, although it looks OK in your editor:

glogin1:$ sbatch MY_SCRIPT
sbatch: error: This does not look like a batch script.  The first
sbatch: error: line must start with #! followed by the path to an interpreter.
sbatch: error: For instance: #!/bin/sh

Solution

Check the file type on the login node with the file command. In the following case

glogin1:$ file MY_SCRIPT
MY_SCRIPT: Bourne-Again shell script, UTF-8 Unicode (with BOM) text executable

you need to remove the byte-order mark (BOM) from the beginning of the file:

glogin1:$ LC_ALL=C sed -i '1s/^\xEF\xBB\xBF//' MY_SCRIPT

Re-check the file type, (with BOM) should have disappeared:

glogin1:$ file MY_SCRIPT
MY_SCRIPT: Bourne-Again shell script, UTF-8 Unicode text executable

For some background and discussion read e.g. here.