0

Hi I want to have "NOTHING HERE" to come out of the for loop but I get NOTHING and HERE

pi@ed_pi:~ $ cat test.txt

NOTHING HERE

pi@ed_pi:~ $ for i in `cat test.txt`; do echo $i; done

NOTHING

HERE

pi@ed_pi:~ $

What am I doing wrong ?

Why are we getting 2 separate $i's ?

Thanks

closed as off-topic by Michael Homer, slm Jan 8 '16 at 3:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Michael Homer, slm
If this question can be reworded to fit the rules in the help center, please edit the question.

4

You get two loop iteration because that is how

for i in value1 value2; do ...

works. You may want

for i in "value1 value2"; do ...

in which case you need

for i in "$(cat test.txt)"; do echo $i; done
  • Thanks very much the "for i in "$(cat test.txt)"; do echo $i; done" did the trick. – user610209 Jan 8 '16 at 2:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.