bash script ": No such file or directory" error
2009-04-06
Why won't my script work? Why do I get this error:
“: No such file or directory ”
when trying to run a script in bash. It worked before!
...and the answer is that your script has picked up windows newline endings.
This is terribly annoying because:
Some broken version control tools convert between Unix and dos line endings when they feel like it
All editors for the last 10 years have handled line endings transparently
Line endings are not displayed by default in most editors
Keeping windows line endings out of version control systems is a PITA
Once you know what is causing the problem the solution is trivial. Either just switch the line ending type in your text editor or use dos2unix:
# sudo apt-get install tofrodos # dos2unix <myscript> # ./myscript
Done!
Well nearly:
# [hg|cvs|svn] blame myscript # Send an email rant, cc'd to the whole development organisation ☻
