delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/08/18/16:45:11

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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
From: "Hannu E K Nevalainen" <_garbage_collector_ AT telia DOT com>
To: <cygwin AT cygwin DOT com>
Subject: RE: read command available?
Date: Wed, 18 Aug 2004 22:44:01 +0200
Message-ID: <NGBBLLIAMFLGJEOAJCCEGECCDNAA._garbage_collector_@telia.com>
MIME-Version: 1.0
In-Reply-To: <Pine.GSO.4.61.0408181051060.28198@slinky.cs.nyu.edu>
X-IsSubscribed: yes

Igor wrote:
> On Wed, 18 Aug 2004, Hannu E K Nevalainen wrote:
>> As I'm not familiar with ksh, so:
>> -- *bash* usage example --
>> #!/bin/bash
>>
>> cd /
>> ls | (
>>   while read TEST ;do
>>     echo -n $TEST
>>   done
>>  )
>
> Two points to note:
>
> 1) there's no need for the parentheses in the above expression --
> in fact,
> they actually change the semantics, as the "while" will be invoked in
> a subshell.

Sorry, bash semantics isn't changed (ksh might be another case, as it's man
page states). bash uses a subshell for the 'while' no matter what you do -
this is obviously considered some kind of optimization, -stupidity IMO (one
has to go to extremes to catch what has been read). I found this out - the
hard way.

Typing the parantheses makes it clear what actually happens; that's why
they're there in the above snippet.

Add a last line of  echo "After loop: $TEST"  above and you'll see the TEST
variable beeing unset; i.e. it was used in a subshell (otherwise it would
hold the last file or dir name).


> 2) the exact same command (with or without the parentheses) works in
> ksh, so I was unable to reproduce the OP's problem.

So does it for me. I never tried it straight OOTB, bugger.


/Hannu E K Nevalainen, B.Sc. EE Microcomputer systems            --72-->

** mailing list preference; please keep replies on list **

-- printf("LocalTime: UTC+%02d\n",(DST)? 2:1); --
--END OF MESSAGE--


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