This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fwd: Problems with line endings for shell scripts


On Tue, Feb 9, 2010 at 9:21 AM, Defurne, Jurgen
<jurgen.defurne@philips.com> wrote:
>
>
> -----Original Message-----
> From: cygwin-owner@cygwin.com [mailto:cygwin-owner@cygwin.com] On Behalf Of Jeremy Bopp
> Sent: 2010 feb 08 16:20
> To: cygwin@cygwin.com
> Subject: Re: Problems with line endings for shell scripts
>
> On 2/8/2010 6:30 AM, Jurgen Defurne wrote:
>> Dear all,
>>
>> I have the following mounts on my test & verification system for Cygwin 1.7.
>>
>> C:/Documents and Settings on /home type ntfs (binary,exec)
>> C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
>> C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
>> C:/cygwin on / type ntfs (binary,auto)
>> C:/local on /usr/local type ntfs (binary,exec)
>> B: on /cygdrive/b type cifs (binary,posix=0,user,noumount,auto)
>> C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
>> E: on /cygdrive/e type cifs (binary,posix=0,user,noumount,auto)
>> H: on /cygdrive/h type netapp (binary,posix=0,user,noumount,auto)
>> Z: on /cygdrive/z type ntfs (binary,posix=0,user,noumount,auto)
>>
>> Today I am having a problem with running a shell script (sh/bash)
>> which has CRLF endings. This is already an old script and has been
>> much used across Cygwin 1.3, 1.5. MontaVista 4.0 and Montavista 5.0.
>>
>> After testing (because Perl does not have a problem), I found out that
>> there is a problem with empty lines in bash.
>>
>> Here is my test case :
>>
>> echo Line to echo
>>
>> echo Another line
>>
>> When running this, I get the output
>>
>> Line to echo
>> run_echo: line 2: $'\r': command not found
>> Another line
>>
>> I also tested it on my portable. There I do not have the problem. The main
>> difference between the two systems is that the OS in the first case is
>> 2003 Server and in the second case Windows XP.
>
> The problem is that Bash only supports Unix line endings, and your
> system is configured to use binary mounts which send the scripts to Bash
> with the Windows line endings intact. ?Your portable most likely has
> text mounts configured which strip the Windows line endings from the
> files on the fly as Bash reads them or is using one of the other
> mechanisms mentioned here:
>
> http://cygwin.com/ml/cygwin-announce/2009-07/msg00002.html
>
> -Jeremy
>
> --
> Problem reports: ? ? ? http://cygwin.com/problems.html
> FAQ: ? ? ? ? ? ? ? ? ? http://cygwin.com/faq/
> Documentation: ? ? ? ? http://cygwin.com/docs.html
> Unsubscribe info: ? ? ?http://cygwin.com/ml/#unsubscribe-simple

To be more complete :

1) These are the mount points on my portable :

C:/Documents and Settings on /home type ntfs (binary)
C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
C:/cygwin on / type ntfs (binary,auto)
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
H: on /cygdrive/h type netapp (binary,posix=0,user,noumount,auto)
P: on /cygdrive/p type netapp (binary,posix=0,user,noumount,auto)
R: on /cygdrive/r type ntfs (binary,posix=0,user,noumount,auto)
S: on /cygdrive/s type netapp (binary,posix=0,user,noumount,auto)
W: on /cygdrive/w type netapp (binary,posix=0,user,noumount,auto)
X: on /cygdrive/x type ntfs (binary,posix=0,user,noumount,auto)

They are all binary.

2) The problem occurs only with EMPTY lines (^\s*$). All lines filled
with commands
execute without problem.

3) The posted solution SHELLOPTS=igncr does help, so this is a general
fix which can
be applied by setting SHELLOPTS under Windows.

Also note that in the past I have never had this problem, and my
scripts and programs
use a mix of CR and CRLF line endings.

Regards,

Jurgen

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]