Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!lll-tis!ptsfa!hoptoad!academ!killer!codas!ge-dab!ge-rtp!edison!uvacs!virginia!scl From: scl@virginia.acc.virginia.edu (Steve Losen) Newsgroups: comp.unix.questions Subject: Re: variables set in sh while loop don't get set? Message-ID: <431@virginia.acc.virginia.edu> Date: Mon, 28-Sep-87 11:26:36 EDT Article-I.D.: virginia.431 Posted: Mon Sep 28 11:26:36 1987 Date-Received: Sun, 11-Oct-87 09:19:49 EDT References: <212@ttrdd.UUCP> Reply-To: scl@virginia.UUCP (Steve Losen) Organization: University of Va., Charlottesville, VA Lines: 28 Keywords: sh, ksh scripts, loops In article <212@ttrdd.UUCP> mellman@ttrdd.UUCP (Thomas Mellman) writes: >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 done # assumed What is happening is that the while loop is being run as a separate process. The shell is very fond of doing this sort of thing, especially in pipelines. At the "done" the "while loop process" exits, giving control back to the parent shell, whose variables haven't changed. I suggest that you do this: pipeline | ( while read proc do # set some variables done # now use the variables set in while loop ) This forces everything between the parentheses to happen in the child process, so you can get some use out of those variables. -- Steve Losen University of Virginia Academic Computing Center