delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/03/25/17:45:15

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Message-ID: <4D8D0CD4.50809@redhat.com>
Date: Fri, 25 Mar 2011 15:44:52 -0600
From: Eric Blake <eblake AT redhat DOT com>
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.9
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: IFS not fixing carriage returns
References: <Pine DOT NEB DOT 4 DOT 64 DOT 1103251116331 DOT 6823 AT panix3 DOT panix DOT com>
In-Reply-To: <Pine.NEB.4.64.1103251116331.6823@panix3.panix.com>
OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg
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

--------------enig6CDE8BFBD9FB2103A591CD29
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

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.

>=20
> 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=3D., 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.

--=20
Eric Blake   eblake AT redhat DOT com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


--------------enig6CDE8BFBD9FB2103A591CD29
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBCAAGBQJNjQzUAAoJEKeha0olJ0Nq484H/0LZAb2Qw8spkq/co2Bwokjx
R4v3oE2hAisS+ZXIMAqt2gBuaQ9xA00q2uqi/4hO6m88mizjAXU7qO4WBPRf8ZIo
EnJqu+hq9pLUQ7qIq8a9H9FhgI1M+XGRWASyK/gwNSPh2ubJrAPNEa2mDGuhuef3
dWsk0TDOd2Og9VFYbA3Ci5rg3oDhHnO5d7ye1NBLaBsohyMGRRpGND8w5VsPKnIz
nGzOAjnkUTJKib+l0JoxAA3MQz9bl3xbv+SYbuOohBrvu9z6HFemoC14nzYcJ447
MeWYyVG22OD/pYnxN74dHDWAvY9rUapF7C51RjVsCKg8FRNx/YYYHVCkeg233a4=
=ljF9
-----END PGP SIGNATURE-----

--------------enig6CDE8BFBD9FB2103A591CD29--

- Raw text -


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