Help with strings in Bourne shell
Stephen J. Friedl
friedl at vsi.COM
Thu Apr 27 00:44:09 AEST 1989
In article <1493 at vsedev.VSE.COM>, logan at 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 at vsi.com / {attmail, uunet, etc}!vsi!friedl
As long as Bush is in office, you'll never see Nancy Reagan in *my* .sig.
More information about the Comp.unix.questions
mailing list