[ale] bash question
Joe Bayes
jbayes at bronze37.mminternet.com
Sat Jun 12 19:16:50 EDT 1999
FCC: ~/.FCC
--text follows this line--
Bob Kruger typeth:
>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
>This
>is
>line2
>This
>is
>line3
That's right, "for" executes the "do" part once for each word in
between "in" and ";". So the above for loop is the same as:
bash$ for f in This is line1
bash> This is line2
bash> This is line3 ;
bash> do echo $f ; done
Since for doesn't care about newlines, this is the same as:
bash$ for f in This is line1 This is line2 This is line3 ; do echo $f ; done
>Any hints on combining the cat command with the for command, and have the
>output look like:
>
>This is line1
>This is line2
>This is line3
I can think of a bunch of ways, but they're all really convoluted, and
mostly involve using either "for" or "cat" in rather trivial
ways. What exactly are you trying to do? There is probably a better
way than using both "for" and "cat".
--joe
More information about the Ale
mailing list