问题原文
原帖链接 · Addy · CC BY-SA 4.0
I have a command that produce a output like this:
$./command1
word1 word2 word3
I want to pass this three words as arguments to another command like this:
$ command2 word1 word2 word3
How to pass command1 output as three different arguments $1 $2 $3 to command2 ?
已采纳解答
原帖链接 · chaos · CC BY-SA 3.0
You can use xargs, with the -t flag xargs will be verbose and prints the commands it executes:
./command1 | xargs -t -n1 command2
-n1 defines the maximum arguments passed to every call of command2. This will execute:
command2 word1
command2 word2
command2 word3
If you want all as argument of one call of command2 use that:
./command1 | xargs -t command2
That calls command2 with 3 arguments:
command2 word1 word2 word3
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
