From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9858 invoked by alias); 6 May 2004 14:20:02 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 9814 invoked from network); 6 May 2004 14:20:00 -0000 Received: from unknown (HELO desmgate.brainlab.com) (62.245.219.4) by sources.redhat.com with SMTP; 6 May 2004 14:20:00 -0000 Received: from 127.0.0.1 (localhost.localdomain [127.0.0.1]) by desmgate.brainlab.com (Postfix) with SMTP id 90ABD25DAF6 for ; Thu, 6 May 2004 16:19:58 +0200 (CEST) Received: from desxch.brainlab.net (host-62-245-219-6.customer.m-online.net [62.245.219.6]) by desmgate.brainlab.com (Postfix) with ESMTP id EBD8225DA7E for ; Thu, 6 May 2004 16:19:26 +0200 (CEST) Received: from DEWXPJAS2 ([62.245.219.5]) by desxch.brainlab.net with Microsoft SMTPSVC(5.0.2195.6713); Thu, 6 May 2004 16:19:26 +0200 Reply-To: From: "Jan Schormann" To: Subject: RE: 'read' and pipes, was: 1.5.9: Trouble with setting variables using 'read' in a script Date: Thu, 06 May 2004 14:22:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit In-Reply-To: <201BC46BD93D244AB0A910D1203FFC1904B6A873@ecexchange02.euphony.com> X-OriginalArrivalTime: 06 May 2004 14:19:26.0864 (UTC) FILETIME=[233D8100:01C43375] X-Spam-Status: No, hits=-105.6 required=5.5 tests=BAYES_10,IN_REP_TO,MSGID_GOOD_EXCHANGE,QUOTED_EMAIL_TEXT, USER_IN_WHITELIST version=2.55 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) X-IsSubscribed: yes X-SW-Source: 2004-05/txt/msg00229.txt.bz2 > Another related quirk, is that variables set within > 'while read' loops lose > their values once the loop ends. The following example > displays "text text" > within the loop and blank line outside. > - echo "text" |\ > while read > do > foo=$REPLY ; bar="text" > echo $foo $bar > done > echo $foo $bar > > Is this a feature of bash or a bug? If it is a feature is there a > workaround? As I learned shortly ago, the pipe '|' always forces a new subshell. This holds for any shell, though someone said that they differ in which side of the pipe gets to be the subshell and which will be executed in the main shell. Thus, in your example, $foo and $bar only exist in the subshell and will never be known to the surrounding shell. I think you can get closer to it using redirection -- 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/