先看下面的命令:
~$ grep bash /etc/passwd
root:x:0:0:root:/root:/bin/bash
guest-rwf0fx:x:116:125:Guest,,,:/tmp/guest-rwf0fx:/bin/bash
但是,如果把结果保存到变量里面:
~$ result=$(grep bash /etc/passwd)
charles@xiaotao:~$ echo $result
root:x:0:0:root:/root:/bin/bash :116:125:Guest,,,:/tmp/guest-rwf0fx:/bin/bash
可以看到,换行符没有了。
加上双引号可以把换行符保留下来:
$ echo "$result"
root:x:0:0:root:/root:/bin/bash
guest-rwf0fx:x:116:125:Guest,,,:/tmp/guest-rwf0fx:/bin/bash