Some questions about the Linux shell script playbook

question 1:
subtitle of p33 page in the book: leave spaces and line breaks by quoting sub-shell.
there are three lines in text.txt, with one number per line, such as 1 2 3
1
2
3
using out=$ (cat text.txt)
echo $out to lose line feeds, and using the method in the book out= "$(cat text.txt)" echo $out still loses newline characters.

[root@centos-linux-7 ~]-sharp uname-r
3.10.0-327.28.3.el7.x86_64


Note: the following applies only to Bash, other shell such as zsh may not be compatible.

typographical error.

out=$ (cat a.txt) has the same effect as out= "$(cat a.txt)" . The key to
is the line echo . Keeping newline characters should enclose the variable echo "$out" in double quotes.

Menu