Path: utzoo!utgpu!watserv1!watmath!att!cbnewsj!ecl From: ecl@cbnewsj.att.com (Evelyn C. Leeper) Newsgroups: comp.unix.questions Subject: Re: What's wrong with this Bourne shell script? Message-ID: <1990Aug5.123522.28149@cbnewsj.att.com> Date: 5 Aug 90 12:35:22 GMT References: <1990Aug3.193231.3166@silma.com> Organization: AT&T Bell Laboratories Lines: 22 In article <1990Aug3.193231.3166@silma.com> aab@silma.UUCP (Andy Burgess) writes: > ----------------------- cut here -------------- > total=0 > ls -ld * | while read line > do > set - `echo $line` > total=`expr $total + $4` > echo "Subtotal $total" > done > echo "Total $total" > ----------------------- cut here -------------- > At the end total prints as 0! > What gives? You cannot export shell variables from a child to a parent. The while loop spawns a subshell and "total" is know only to the subshell. [Note: can someone arrange to have this put in the "commonly asked questions" posting?] Evelyn C. Leeper | +1 908-957-2070 | att!mtgzy!ecl or ecl@mtgzy.att.com -- The only thing necessary for the triumph of evil is for good men to do nothing. -Edmund Burke