在 linux 命令列中,可以使用語法
command1 $(command2)將 command2 的輸出用作 command1 的引數。例如,如果我有一個test.txt包含 content
的檔案this\ is\ a\ test,我可以使用(在這種情況下是胡說八道)
echo $(cat test.txt)
來回顯cat test.txt. 然而,這以一種奇怪的方式解釋了轉義序列:命令
的輸出echo -e this\ is\ a\ test是this is a test,而輸出
echo -e $(cat test.txt)是this\ is\ a\ test。轉義序列不會被這樣解釋。有誰知道這是為什么?
uj5u.com熱心網友回復:
用set -x來看區別:
$ cat file
this\ is\ a\ test
$ set -x
$ echo -e this\ is\ a\ test
echo -e 'this is a test'
this is a test
$ echo -e 'this\ is\ a\ test'
echo -e 'this\ is\ a\ test'
this\ is\ a\ test
$ echo -e $(cat file)
cat file
echo -e 'this\' 'is\' 'a\' test
this\ is\ a\ test
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/422228.html
標籤:
上一篇:僅列出在Bash中使用ls的目錄,但保留ls格式且沒有目錄名
下一篇:bash手動回圈遍歷目錄中的檔案
