2015-11-08 19 views
0

看起來像尾隨'\n'字符被修剪爲"$()",,而我從bash manual找不到關於此的任何規範。這真的讓人困惑,任何人都可以幫我解釋一下嗎?

[[email protected]_6_207_centos ~]$ a="$(echo $'abc\n\n' | cat)" 
[[email protected]_6_207_centos ~]$ echo "$a" 
abc 
[[email protected]_6_207_centos ~]$ a="$(echo $'abc\n\nb' | cat)" 
[[email protected]_6_207_centos ~]$ echo "$a" 
abc 

b 
[[email protected]_6_207_centos ~]$ a=$'abc\n' 
[[email protected]_6_207_centos ~]$ echo "$a" 
abc 

[[email protected]_6_207_centos ~]$ a="$(echo $'abc ' | cat)" 
[[email protected]_6_207_centos ~]$ echo "$a" | url_encode 
abc%20%20%0A[[email protected]_6_207_centos ~]$ 

回答

0

好,我剛發現從manual

擊執行由執行命令和與該命令,with any trailing newlines deleted. Embedded newlines are not deleted的標準輸出替換 命令替換膨脹的解釋,但是它們 可以在分詞期間被刪除。命令替換$(cat 文件)可以被替換爲等效但更快的$(<文件)。