-bash-4.1# cat output
"/root/mail/domain.com/root/Archive 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.


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"
| 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. – user9517 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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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