Path: utzoo!attcan!uunet!abcfd20.larc.nasa.gov!news.larc.nasa.gov!scott From: scott@tab29.larc.nasa.gov (Scott Yelich (ODU) ) Newsgroups: comp.unix.questions Subject: Re: What's wrong with this Bourne shell script? Message-ID: Date: 7 Aug 90 13:01:49 GMT References: <1990Aug3.193231.3166@silma.com> <1990Aug5.123522.28149@cbnewsj.att.com> Sender: news@abcfd20.larc.nasa.gov (USENET File Owner) Organization: NASA Langley Research Center, Hampton, Va. 23665 Lines: 47 In-Reply-To: ecl@cbnewsj.att.com's message of 5 Aug 90 12:35:22 GMT 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? As it has been said: It should. However, I fiddle around with SH scripts... and this is how I would hack your script: 1) I would not do it in perl-- I hate it when people ask about bourne shell and other people reply with perl.... #!/bin/sh set - `ls -ld *` while test "$6" do shift 3 EXPR="$1 + $EXPR" shift 5 done echo "Total=`expr $EXPR 0 `" Not that it really matters.... but there isn't a pipe in there nor so many calls to expr... Of course, I didn't assign the variable total anywhere... unless you are going to use it somewhere else, it isn't needed and it looked like you were just using it as a counter... Scott -- Signature follows. [Skip now] ----------------------------------------------------------------------------- Scott D. Yelich scott@[xanth.]cs.odu.edu [128.82.8.1] After he pushed me off the cliff, he asked me, as I fell, ``Why'd you jump?'' Administrator of: Game-Design requests to ODU/UNIX/BSD/X/C/ROOT/XANTH/CS/VSVN/ -----------------------------------------------------------------------------