Red Hat Bugzilla – Bug 60933
Shell scripts with DOS newlines fail to execute.
Last modified: 2007-04-18 12:40:48 EDT
Description of Problem:
If the first line (at least) of a bash shell script is terminated with
the DOS newline, i.e., <CR><LF>, the script will fail to execute,
yielding the message "No such file or directory."
Although such behavior might be considered "correct", it can be
very confusing for the unwary since at least one of the standard
editors (vi/vim) doesn't display the <CR> character, nor does the
<CR> appear if the script is 'cat' to the terminal.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Create example script "bashlin":
echo "running script"
2. Create similar script "bashdos" with DOS newlines:
$ unix2dos -n bashlin bashdos
3. Make both scripts executable:
$ chmod 777 bashlin bashdos
4. Attempt to execute both scripts:
Script "bashlin" works as expected.
Script "bashdos" fails to execute with the message "No such file or directory".
Both scripts ought to execute, or at least provide a more descriptive
error message upon failure.
Shell tcsh has the same problem.
This is the intended behavior.
DOS-style newlines put a \r character before the real newline, so the shell tries to
which of course doesn't exist (but might - there's nothing that prevents you from using
this character in a filename).