Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

-bash-4.1# cat output
"/root/mail/ Dir.2012.04 April"

for i in `cat output`; do echo "$i"; done

I want them on a single line, as they are originally stored in the file. Is it echo's fault?
echo -n will break everything, so it won't do.

share|improve this question

You can use a while loop

while read i 
    echo $i
done < output

The reason why your command doesn't work as you expect is that for operates on words. The value of the $IFS variable determines what characters are used to delimit words, the default is space, tab and newline. As your input file contains lines that have spaces they are being spit into words. If you need to use a for loop you can work around this by wraping your lines in "

for i in "`cat output`"
    echo "$i"
share|improve this answer
hmpf, same error when replacing echo with mkdir, in both for and while. – w00t Nov 21 '12 at 11:10
@w00t: Yes and it will be for exactly the same reason. I'll leave it as an exercise for you to figure it our yourself. This is all very basic stuff you should invest some time in learning the tools you're working with rather than blundering from one problem to the next. It'll save you lots of time in the long run. – Iain Nov 21 '12 at 11:57
it works with echo, why shouldn't it work with any other command? Again, it does the same even when using while – w00t Nov 22 '12 at 12:18
while read line; do echo $line; done < output
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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