delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/02/09/03:41:38

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <d37e30051002090038y113f961exc7b52f76c31ec68c@mail.gmail.com>
References: <30C00ED8C6EFC24B981DB4936876D464A72D804D59 AT NLCLUEXM07 DOT connect1 DOT local> <d37e30051002090038y113f961exc7b52f76c31ec68c AT mail DOT gmail DOT com>
Date: Tue, 9 Feb 2010 09:41:20 +0100
Message-ID: <d37e30051002090041v56086059lcc08ff1c93335448@mail.gmail.com>
Subject: Fwd: Problems with line endings for shell scripts
From: Jurgen Defurne <jurgen DOT defurne AT gmail DOT com>
To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Tue, Feb 9, 2010 at 9:21 AM, Defurne, Jurgen
<jurgen DOT defurne AT philips DOT com> wrote:
>
>
> -----Original Message-----
> From: cygwin-owner AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com] On Behalf =
Of Jeremy Bopp
> Sent: 2010 feb 08 16:20
> To: cygwin AT cygwin DOT 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=3D0,user,noumount,auto)
>> C: on /cygdrive/c type ntfs (binary,posix=3D0,user,noumount,auto)
>> E: on /cygdrive/e type cifs (binary,posix=3D0,user,noumount,auto)
>> H: on /cygdrive/h type netapp (binary,posix=3D0,user,noumount,auto)
>> Z: on /cygdrive/z type ntfs (binary,posix=3D0,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 ma=
in
>> 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. =A0Your 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: =A0 =A0 =A0 http://cygwin.com/problems.html
> FAQ: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 http://cygwin.com/faq/
> Documentation: =A0 =A0 =A0 =A0 http://cygwin.com/docs.html
> Unsubscribe info: =A0 =A0 =A0http://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=3D0,user,noumount,auto)
H: on /cygdrive/h type netapp (binary,posix=3D0,user,noumount,auto)
P: on /cygdrive/p type netapp (binary,posix=3D0,user,noumount,auto)
R: on /cygdrive/r type ntfs (binary,posix=3D0,user,noumount,auto)
S: on /cygdrive/s type netapp (binary,posix=3D0,user,noumount,auto)
W: on /cygdrive/w type netapp (binary,posix=3D0,user,noumount,auto)
X: on /cygdrive/x type ntfs (binary,posix=3D0,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=3Digncr 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019