Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!vsi!friedl From: friedl@vsi.COM (Stephen J. Friedl) Newsgroups: comp.unix.questions Subject: Re: Help with strings in Bourne shell Summary: A common Bourne shell mistake Message-ID: <1107@vsi.COM> Date: 26 Apr 89 14:44:09 GMT References: <10166@orstcs.CS.ORST.EDU> <1493@vsedev.VSE.COM> Distribution: usa Organization: V-Systems, Inc. -- Santa Ana, CA Lines: 43 In article <1493@vsedev.VSE.COM>, logan@vsedev.VSE.COM (James Logan III) writes: > > BTW, you can also read from a specific file by redirecting the > input to the read command like this: > > while read DEFINITION < inputfile; do > echo "$DEFINITION"; > # other stuff > done; This is a common mistake. The redirection applies to only the read command, and every time the while hits the read, the input file is opened anew and the same first line is read over and over (and the while never terminates). Try: while read line < /etc/passwd ; do echo $line done and you'll learn your encrypted root password quite well. The {Bou,Ko}rn shells support piping and redirection into and out of control flow, so things like: while read foo ; do stuff here done < inputfile or while condition ; do stuff here done > outputfile or grep stuff file | while read line ; do .... ; done all do things that make sense. Steve -- Stephen J. Friedl / V-Systems, Inc. / Santa Ana, CA / +1 714 545 6442 3B2-kind-of-guy / friedl@vsi.com / {attmail, uunet, etc}!vsi!friedl As long as Bush is in office, you'll never see Nancy Reagan in *my* .sig.