Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!boulder!stan!dce From: dce@stan.UUCP (David Elliott) Newsgroups: comp.unix.questions Subject: Re: Some csh how-to, please Keywords: csh C-shell shell programming unix read Message-ID: <718@salgado.stan.UUCP> Date: 3 Apr 89 15:38:48 GMT References: <2127@pikes.Colorado.EDU> <7467@thorin.cs.unc.edu> <1175@Portia.Stanford.EDU> <4258@omepd.UUCP> Reply-To: dce@Solbourne.com (David Elliott) Organization: Solbourne Computer Inc., Longmont, Colorado Lines: 55 In article <4258@omepd.UUCP> merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) writes: >Why do people use 'cat' at every opportunity? Maybe that's why >they sell so many multiprocessor machines? :-) :-) >Simpler: > > while read fie > do > something with $fie > done >no additional processes. I agree with you in principle. It is silly to use cat and a pipe when simple redirection will work. In practice, you are unfortunately wrong. The best that redirection gives you is one less exec. Current "standard" versions of sh (in other words, most sh's other than ksh) fork when redirection is done on a loop. Try this script: #!/bin/sh PLACE=out while read line do PLACE=in done < /etc/group echo "PLACE is $PLACE" exit 0 The output on my system (SunOS 4.0.1) is PLACE is out A better solution is exec 3<&0