Bug 60933 - Shell scripts with DOS newlines fail to execute.
Shell scripts with DOS newlines fail to execute.
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: bash (Show other bugs)
7.1
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: wdovlrrw
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-03-09 11:40 EST by Charles Sullivan
Modified: 2007-04-18 12:40 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-03-09 11:41:02 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Charles Sullivan 2002-03-09 11:40:58 EST
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):
N/A

How Reproducible:
Always

Steps to Reproduce:
1.  Create example script "bashlin":
-----------------
#!/bin/bash
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:
$  ./bashlin
$  ./bashdos

Actual Results:
Script  "bashlin" works as expected.
Script  "bashdos" fails to execute with the message "No such file or directory".

Expected Results:
Both scripts ought to execute, or at least  provide a more descriptive
error message upon failure.

Additional Information:
Shell tcsh has the same problem.
Comment 1 Bernhard Rosenkraenzer 2002-03-11 05:13:09 EST
This is the intended behavior. 
DOS-style newlines put a \r character before the real newline, so the shell tries to 
launch 
 
appname\r 
 
which of course doesn't exist (but might - there's nothing that prevents you from using 
this character in a filename). 

Note You need to log in before you can comment on or make changes to this bug.