delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/10/23/21:07:41

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
From: "Cutler, David" <david DOT cutler AT hp DOT com>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Date: Wed, 24 Oct 2007 01:06:58 +0000
Subject: RE: Bug in cat
Message-ID: <C9EE75BD336E954CB33E9E3E6CBCACB1230A918138@G3W1111.americas.hpqcorp.net>
References: <C9EE75BD336E954CB33E9E3E6CBCACB1230A9180C2 AT G3W1111 DOT americas DOT hpqcorp DOT net> <471E9797 DOT 84584AF2 AT dessent DOT net>
In-Reply-To: <471E9797.84584AF2@dessent.net>
Accept-Language: en-US
acceptlanguage: en-US
MIME-Version: 1.0
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
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id l9O17UIO009252

Hi Brian,

It makes sense to me.   I like your recommended replacement too.

Thanks,

-Dave

-----Original Message-----
From: Brian Dessent [mailto:brian AT dessent DOT net]
Sent: Tuesday, October 23, 2007 5:54 PM
To: Cutler, David
Cc: bug-coreutils AT gnu DOT org
Subject: Re: Bug in cat

"Cutler, David" wrote:

> When I downloaded Cygwin, I specified the use of DOS line terminators.
>
> I found a bug in what I suspect is cat when used with a simple bash shell script.

Since you're using Cygwin, the Cygwin mailing list is a better place to post this because most coreutils developers don't use Cygwin.

This is not technically a bug however, because cat always works in binary mode by design regardless of mount mode.  This is required by POSIX I believe.  Eric has mentioned in the past adding a Cygwin-specific --text option to cat but any time you start to maintain special patches it makes maintainer burden go up.  Even then, you would have to give the option explicitly.

And besides, there are much better ways to deal with this:

> And you execute the command:
>    for I in `cat list` ; do echo \"${i}\" ; done

Inefficient.  Instead you can simply:

while read i; do echo \"${i}\"; done <list

This has the following advantages:

- no need to spawn a subshell process plus a cat subprocess (this is very slow on Cygwin)
- since the file is opened by bash it obeys the mount table settings

If you must use backticks, pipe the output through d2u.  You can also set the 'nobinmode' parameter of $CYGWIN which effects the mode of pipes (which are used with the backtick operator), turning them into text by default.  However this is quite dangerous as it breaks commands that expect to pass binary files through pipes, such as tar/gzip/bzip2.

Brian

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


- Raw text -


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