shell 将两个参数传递给同一行中的另一个命令[duplicate]

iovurdzv  于 2023-02-13  发布在  Shell
关注(0)|答案(1)|浏览(125)
    • 此问题在此处已有答案**:

Is it possible to insert arguments at different points in a command in linux while piping(2个答案)
昨天关门了。
我需要给同一个命令传递两个参数。第一个命令的输出如下所示:

BLA    BLE
A1     B2
A2     B3

现在我用这个来使用第一个参数

firstCommand | tail -n1 | awk '{print $1}' | xargs -I_ secondCommand _

但secondCommand已更改,现在我需要传递第二个参数

secondComman A --second B

使用xargs可以实现这一点吗?
我尝试了多个堆栈溢出解决方案,但都不成功。

mpgws1up

mpgws1up1#

将打印第2个参数添加到awk,并使用xargs捕获2个参数:

firstCommand | tail -n1 | awk '{print $1,$2}' | xargs -n2 sh -c 'secondCommand "$1" --second "$2"' _

相关问题