[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] bash question
- Subject: [ale] bash question
- From: mic at mathcs.emory.edu (Michelangelo Grigni)
- Date: Sat, 12 Jun 1999 21:46:22 -0400 (EDT)
> == joe
> > == bob
> >If I give the bash command cat t1.txt, I get the following
> >
> >This is line1
> >This is line2
> >This is line3
> >
> >However, if I do:
> >
> >for f in `cat t1.txt` ; do echo $f ; done
> >
> >I get the following
> >
> >This
> >is
> >line1
> ...
> I can think of a bunch of ways, but they're all really convoluted
This is a job for the shell IFS variable. Just set it to
contain a single newline, and then each line will be
treated as a single input field. Like this:
IFS='
'
for f in `cat t1.txt` ; do echo $f ; done
Or like this, without cat:
IFS='
'
while read f; do echo $f; done < t1.txt
You may need to restore IFS to its default, depending on
what else you do in the script.