所以,命令:慶典/ SH -c無法與多個管道工作
dmesg | grep 'Attached SCSI disk' | awk '{ print $5}'
當從外殼直接執行,就像它應該輸出:
[sdb]
[sdc]
[sda]
但是,當我與啓動它:
sh -c "dmesg | grep 'Attached SCSI disk' | awk '{ print $5}'"
# or
bash -c "dmesg | grep 'Attached SCSI disk' | awk '{ print $5}'"
我得到:
[ 2.460353] sd 1:0:0:0: [sdb] Attached SCSI disk
[ 2.461348] sd 2:0:0:0: [sdc] Attached SCSI disk
[ 2.464181] sd 0:0:0:0: [sda] Attached SCSI disk
這清楚地表明,過去的管還沒有執行。
我在做什麼錯?
另外,反模式'grep x | awk'{stuff}''通常可以簡化爲'awk'/ x/{stuff}' – tripleee