I have a file with several lines.
When using cat/more/less [file] in the shell,
the content is shown line by line
When doing the following commands:
temp=`cat [file]`
echo $temp
the content is shown in one line.
Is there a way to preserve the line endings when setting to environment variable and then echo it?
Thanks
Yes:
The magic is in the quotes around
$temp; without them,echogets these arguments:The shell parsing algorithm will split the command line at white space, so
echosees three arguments. If you quote the variable,echowill see a single argument and the shell parsing won’t touch the whitespace between the quotes.