4th Oct 2013
Line endings and Bash red herrings
It's just taken a colleague and I a number of hours — on release day, naturally — to track down a fault with a shell script, because Bash was unclear in its error reporting:
Performing firmware upgrade...
./v2.14~test.bin: line 172: /tmp/upgrade-hw.sh: not found
[xy765 /root]# cd /tmp
[xy765 /tmp]# ls -l upgrade-hw.sh
-rwxrwxr-x 1 503 504 3414 Oct 4 12:09 upgrade-hw.sh
The file is obviously not "not found", but it turned out that upgrade-hw.sh
had recently been imbued with DOS-type line endings (which affected every line including the first one with the shebang "#!/bin/bash
") and it was, in fact, the "/bin/bash^M
" program that could not be found!
A lesson to us all…