Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!haven!vrdxhq!vsedev!logan From: logan@vsedev.VSE.COM (James Logan III) Newsgroups: comp.unix.questions Subject: Re: Help with strings in Bourne shell Message-ID: <1496@vsedev.VSE.COM> Date: 28 Apr 89 02:37:50 GMT References: <10166@orstcs.CS.ORST.EDU> <1493@vsedev.VSE.COM> Reply-To: logan@vsedev.VSE.COM (James Logan III) Distribution: usa Organization: VSE Software Development Lab Lines: 47 In article <1493@vsedev.VSE.COM> I wrote: # BTW, you can also read from a specific file by redirecting the # input to the read command like this: # # INPUTFILE="some_file"; # # while read DEFINITION <$INPUTFILE; do # echo "$DEFINITION"; # . # . # . # done; Oooops, I screwed up! What I wrote above will read the first line again and again! The best solution is: INPUTFILE="some_file"; exec 4<$INPUTFILE; while read DEFINITION 0<&4; do echo "$DEFINITION"; . . . done; exec 4<&-; since the alternative construct: INPUTFILE="some_file"; while read DEFINITION; do echo "$DEFINITION"; . . . done <$INPUTFILE; has the side-effect of redirecting the input of every command invoked from within the while loop. -Jim -- Jim Logan logan@vsedev.vse.com VSE Software Development Lab uucp: ..!uunet!vsedev!logan (703) 329-4654 inet: logan%vsedev.vse.com@uunet.uu.net