我创建了一个如下所示的变量:
firstAndLastLines="$(cat /etc/passwd | head -$n | cut -f5 -d':') $(cat /etc/passwd | tail -$n | cut -f5 -d':') "
如果我使用 echo $firstAndLastLines
将它打印到终端,我会得到以下输出:
root bin daemon adm lp trousers 包用来对 tcsd daemon Norbert Fogarasi 进行沙盒处理的特权分离 SSH 帐户
但是,如果我使用 echo "$firstAndLastLines"
,我会得到以下内容,以新行分隔:
root
bin
daemon
adm
lp
Privilege-separated SSH
Account used by the trousers package to sandbox the tcsd daemon
Norbert Fogarasi`
我想知道,为什么会这样?它不必是相同的? `
最佳答案
在 bash man 中的解释:
Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, \,
关于linux - bash 脚本中双引号的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44778677/