From Bash manual about the result of command expansion
Embedded newlines are not deleted, but they may be removed during word splitting.
For example
$ cat myfile
1
2
3
$ echo $(cat myfile)
1 2 3
I wonder why embedded newlines are replaced with whitespaces? The manual doesn't say so, does it?
removed during word splitting
– Michael Homer Mar 06 '16 at 08:33echo $(cat myfile)
, does the bash manual say why the words are separated by white spaces, instead of not being seperated? – Tim Mar 06 '16 at 08:48$(...)
in double-quotes. The entire output of the command-substitution will be treated as a single string. e.g.echo "$(cat myfile)"
– cas Mar 07 '16 at 03:39