Convert Windows-style line endings (CRLF) to Unix-style (LF)
June 08, 2025When executing a downloaded shell script, you might encounter the error syntax error: unexpected end of file (expecting "do")
. This is often due to improper line endings.
To fix this issue:
-
Convert Windows-style line endings (CRLF) to Unix-style (LF):
cat yourscript.sh | tr -d '\r' > yournewscript.sh
-
Verify the line endings by looking for
0d 0a
sequences using thehexdump
command:hexdump -C yourscript.sh
By removing the 0d
characters, your script should execute without syntax errors.