Bug 60933 - Shell scripts with DOS newlines fail to execute.
Summary: Shell scripts with DOS newlines fail to execute.
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: bash
Version: 7.1
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: wdovlrrw
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-03-09 16:40 UTC by Charles Sullivan
Modified: 2007-04-18 16:40 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-03-09 16:41:02 UTC
Embargoed:


Attachments (Terms of Use)

Description Charles Sullivan 2002-03-09 16:40:58 UTC
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 10:13:09 UTC
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.