Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!swbatl!texbell!ficc!peter From: peter@ficc.ferranti.com (Peter da Silva) Newsgroups: comp.unix.questions Subject: Re: What's wrong with this Bourne shell script? Message-ID: <4K15H:A@xds13.ferranti.com> Date: 7 Aug 90 19:01:00 GMT References: <1990Aug3.193231.3166@silma.com> Organization: Xenix Support, FICC Lines: 24 In article <1990Aug3.193231.3166@silma.com>, aab@silma.com (Andy Burgess) writes: > total=0 > ls -ld * | while read line ... > echo "Total $total" Unfortunately, that while loop is run by a subshell. Try this: total=0 ls -ld * | { while read line ... echo "Total $total" } Or (better) use AWK: ls -ld * | awk '{ total=total+$4; print "Subtotal " total } END { print "Total " total }' (Someone will come up with a PERL version, 'tis certain) -- Peter da Silva. `-_-' +1 713 274 5180. 'U`