Fixing Scripts Written in Windows
Do you get obscure errors like "\r: command not found" or "/bin/bash^M: bad interpreter" when trying to run your scripts on an SuperCloud system? If so, the most likely explanation is that the script file was created in an editor on Windows and then copied to the SuperCloud.
In this example, the file test.sh
was created on a Windows system and
copied to SuperCloud.
When we try to run this script, we get an error:
Text files created on DOS/Windows machines have different line endings
than files created on Linux (which is the OS that the SuperCloud system runs).
DOS uses carriage return and line feed (\r\n
) as a line ending,
while Linux uses just a line feed (\n
). You need to be careful when
transferring files between Windows machines and the SuperCloud system to make
sure the line endings are translated properly.
From the the login node of a SuperCloud system, you can see what line endings
a text file contains by running the cat -vet
command on the file:
If you see ^M$
at the end of each line, then this file will not run on
a Linux system. If you see just $
at the end of each line, then it is
properly formatted to run on a Linux system.
There's a simple way to convert your DOS formatted file to Linux
format - just run the command dos2unix
on the file:
Verify that the line endings are Linux line endings:
Try running the script again: