Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!RODAN.ACS.SYR.EDU!jdpeek From: jdpeek@RODAN.ACS.SYR.EDU (Jerry Peek) Newsgroups: comp.unix.questions Subject: Re: Bourne Shell FOR loop confusion Message-ID: <8908201819.AA04967@rodan.acs.syr.edu> Date: 20 Aug 89 19:19:13 GMT References: <2999@solo1.cs.vu.nl> <689@msa3b.UUCP> <2346@wyse.wyse.com> <8908131325.AA28606@rodan.acs.syr.edu> Sender: daemon@ucbvax.BERKELEY.EDU Lines: 25 In article <2999@solo1.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: < jdpeek@RODAN.ACS.SYR.EDU (Jerry Peek) writes: < \... while read user passwd uid junk < \ do < \ line=`expr $line + 1` < \ echo "user${line}='$user' uid${line}='$uid'" 1>&4 < \ done $defs < < Why use fd 4, Jerry? Stdout will do. Oops. To keep from wasting net bandwidth, I left out things like the error checking (with output to stderr, fd2): echo "`basename $0`: warning: bad line $line" 1>&2 Also, the stdout of the loop (fd1) went to a pipe: done $defs | some-other-program-or-loop That's why I used fd4 for the variable definitions. BTW, Chris Torek sent mail and pointed out that using fd4 takes time for the extra dup() calls that the shell has to do. Chris didn't know that I'd left out some of the code, but he still has a good point. --Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY jdpeek@rodan.acs.syr.edu///JDPEEK@SUVM.BITNET///GEnie: J.PEEK1 +1 315 443-3995