在 GNU Bash 中,diff <(df) <(ls)
正在運行。
在 中sh
,事實並非如此。
我也嘗試了[[diff </bin/df <bin/ls]]
,仍然報錯:
$ [[/usr/bin/diff < (/bin/ls) < (bin/df)]]
sh: 1: Syntax error: "(" unexpected
$ bash
有誰知道相當於sh
?非常感謝您的幫忙。
答案1
沒有與<(…)
>(…)
替換直接等效的東西 - 您需要手動建立命名管道作為替換:
mkfifo /tmp/lspipe
mkfifo /tmp/dfpipe
/bin/ls > /tmp/lspipe &
/bin/df > /tmp/dfpipe &
/usr/bin/diff /tmp/lspipe /tmp/dfpipe
rm /tmp/lspipe /tmp/dfpipe
(另請注意,在 Bash 中,有不<
和之間有空格(…)
。
在這種情況下,這[[…]]
完全沒有意義。它們不是用於分組命令,而是用於編寫條件表達式(不要將它們與( )
or { }
which do 分組命令混淆)。它也是 Bash 特有的功能,但在正確使用它的地方,它可以替換為[ … ]
或expr
。