我想比較一個程式在兩個檔案上的輸出。它會是這樣的:
comm -23 <(cat a/somefile) <(cat b/somefile)
cat指揮怪物的替身在哪里。
這是我所知道的。如果我這樣做,echo {a,b}/somefile那么我得到
a/somefile b/somefile
哪個是正確的。
我試圖將這種“爆炸”應用于程序替換:comm -23 <(cat {a,b}/somefile)不用說我得到了一個錯誤comm: missing operand after ‘/proc/self/fd/16’。這有可能嗎?
uj5u.com熱心網友回復:
該{a,b}語法是一種形式的括號擴展,但其范圍是有限的。它不會重復它左側的所有內容:
$ echo cat {a,b}/somefile
cat a/somefile b/somefile
但是,如果有任何東西“接觸”左大括號:
$ echo cat{a,b}/somefile
cata/somefile catb/somefile
回到您的示例,該<(cat {a,b}/somefile)部分擴展為<(cat a/somefile b/somefile),它只會連接兩個檔案的內容并將它們放入由行程替換創建的臨時檔案中。但是comm需要兩個引數,而不是一個,這就是您收到錯誤的原因。你知道這一點,但我猜你對大括號擴展的行為(它擴展的范圍)有不同的期望。
我建議您使用“命令的怪物”創建自己的函式,并在兩個行程替換中重用它:
monster() {
cat "$@"
}
comm -23 <(monster a/somefile) <(monster b/somefile)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/314570.html
標籤:猛击
上一篇:php網頁不執行腳本
