0

-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.

w00t
  • 1,134
  • 3
  • 16
  • 35

2 Answers2

3

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
user9517
  • 114,104
  • 20
  • 206
  • 289
  • 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
2
while read line; do echo $line; done < output
Laurentiu Roescu
  • 2,246
  • 16
  • 17