Mail Archives: cygwin/2004/08/18/16:45:11
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 -