Line at a time scripts in csh
00771g-Lukas
lukas at ihlpf.ATT.COM
Thu Jan 19 00:22:52 AEST 1989
In article <4116 at paris.ics.uci.edu> posert at bonnie.ics.uci.edu (Bob Posert) writes:
>
>I have a file with two words on each line, and want to
>process them in a shell script, but can't figure out
>how to get *the entire line* into a variable.
Nobody mentioned IFS, so I thought Id through my $.02 in. The following
will I think solve the problem:
ifs_def=$IFS
ifs_nl="\
"
while read in; do
echo "$in"
# other stuff
IFS="$ifs_nl"
done <t.in
IFS="$ifs_def"
Now, Im not sure why the IFS change surrounds the redirection (my first
impulse was to have it surround the "read"), however, it works
correctly (empirically). It handles leading white space and special
characters correctly. It has the additional benefit of
working with sh, ksh, and csh.
--
John Lukas
att!ihlpf!lukas
312-510-6290
More information about the Comp.unix.questions
mailing list