delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/05/26/10:30:32

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.6 required=5.0 tests=BAYES_00,DATE_IN_PAST_24_48,SPF_HELO_PASS,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Luke Kendall <luke AT zeta DOT org DOT au>
Subject: Re: IFS not fixing carriage returns
Date: Wed, 25 May 2011 07:34:53 +0000 (UTC)
Lines: 44
Message-ID: <loom.20110525T093223-608@post.gmane.org>
References: <Pine DOT NEB DOT 4 DOT 64 DOT 1103251116331 DOT 6823 AT panix3 DOT panix DOT com> <4D8D0CD4 DOT 50809 AT redhat DOT com>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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

Eric Blake <eblake <at> redhat.com> writes:

> 
> On 03/25/2011 10:35 AM, Tim McDaniel wrote:
> > Although it's not documented in "man bash" on the latest Cygwin, I did
> > find "set -o igncr" and it seems to work well.
> 
> I documented it in the cygwin bash release notes, so it is in
> /usr/share/doc/Cygwin/bash.README.  Patches welcome if you want to see
> it somewhere else like the man page, because that takes more effort.
> 
> > 
> > But I'm just curious about why my first attempt didn't work.
> 
> IFS only affects word splitting _after words have been parsed and
> expansions performed_.  Bash does _not_ ignore CR in the input stream
> while parsing words, regardless of the IFS settings.  Let's use a
> simpler example:
> 
> If you set IFS=., then echo a.b will still only echo the one word "a.b"
> and not split into two words "a" and "b", because '.' is not special in
> determining word boundaries (a.b is a single word), and there was no
> expansion going on.
> 
> And it would be prohibitively expensive to make shells honor random IFS
> while parsing out words, so bash _only_ uses space, tab, and newline to
> determine word boundaries, not carriage return.
> 
> That's why igncr is more powerful than IFS - it strips the CR prior to
> the point that bash is even trying to parse the line into words.
> 


Can I urge this option be added into the upstream bash, so it's available under
Linux versions too?  I want to run scripts that work with some text files that
have come from Windows and it would be extremely useful.  If I use it now
however, in bash version 4.0.33(1)-release (i486-pc-linux-gnu) I get:

+ set -o igncr
set: 1: Illegal option -o igncr

So the script is not portable between Windows and Linux.

luke


--
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