Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

for i in `cat output`; do echo "$i"; done
"/root/mail/domain.com/root/Archive
Dir.2012.04
April"

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

2 Answers 2

You can use a while loop

while read i 
do
    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`"
do
    echo "$i"
done
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

 
discard

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.