0

I have a file with 3 separate lines, when I read the file content into a variable, for some reason the new lines are replaced with spaces, how can I prevent it so the variable will contain new lines instead spaces?

[root@ tmp]# cat xxx
aaa
bbb
ccc
[root@ tmp]# x=`cat xxx`
[root@ tmp]# echo $x
aaa bbb ccc
[root@ tmp]# echo $x | od -c
0000000   a   a   a       b   b   b       c   c   c  \n
0000014
[root@ tmp]# cat xxx | od -c
0000000   a   a   a  \n   b   b   b  \n   c   c   c  \n
0000014
e271p314
  • 3,841
  • 7
  • 36
  • 61
  • 2
    `x` contains the correct content, but it is mangled since you did not quote `$x`. Use `echo "$x"`. – Socowi Jan 23 '19 at 10:46
  • @Socowi you are correct `echo "$x"` indeed shows new lines instead spaces, thanks for the prompt response – e271p314 Jan 23 '19 at 10:51

0 Answers0