Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!linus!necntc!ames!ptsfa!ihnp4!cbosgd!mandrill!abvax!crc From: crc@abvax.icd.ab.com (Clive R. Charlwood) Newsgroups: comp.unix.questions Subject: Re: variables set in sh while loop don't get set? Message-ID: <71@abvax.icd.ab.com> Date: Mon, 28-Sep-87 18:50:07 EDT Article-I.D.: abvax.71 Posted: Mon Sep 28 18:50:07 1987 Date-Received: Wed, 30-Sep-87 07:22:08 EDT References: <212@ttrdd.UUCP> Organization: Allen-Bradley Company, Inc; Industrial Computer Division, Highland Heights, OH Lines: 32 in article <212@ttrdd.UUCP>, mellman@ttrdd.UUCP (Thomas Mellman) says: > > When I set a variable in a while loop in a sh script, in some scripts > it doesn't seem to get set. For example, a common thing is to do a > > pipeline | while read proc > do > > and then to test for some condition in a case statement. Twice now, I > have written scripts where a variable set in the case loop (or anywhere > in the while loop, for that matter) won't have been changed from its > initial value after the while loop terminates. Can anyone explain to me > why this is so. In the bourne shell while/for loops that have stdin redirected are implemented as sub shells. Thus any changes to variables 'disapear' when the shell exits. Clive Clive R. Charlwood @ Allen-Bradley Company Industrial Computer Division 747 Alpha Drive, Highland Heights, OH 44143 ...!{decvax,masscomp,pyramid,cwruecmp}!abic!crc -- Clive R. Charlwood @ Allen-Bradley Company Industrial Computer Division 747 Alpha Drive, Highland Heights, OH 44143 ...!{decvax,masscomp,pyramid,cwruecmp}!abic!crc