如何将命令输出作为多个参数传递给另一个命令 [英] How to pass command output as multiple arguments to another command
本文介绍了如何将命令输出作为多个参数传递给另一个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将命令的每个输出作为多个参数传递给第二个命令,例如:
I want to pass each output from a command as multiple argument to a second command, e.g.:
grep "pattern" input
返回:
file1
file2
file3
,我想复制这些输出,例如:
and I want to copy these outputs, e.g:
cp file1 file1.bac
cp file2 file2.bac
cp file3 file3.bac
我该怎么做呢?像这样:
How can I do that in one go? Something like:
grep "pattern" input | cp $1 $1.bac
推荐答案
您可以使用xargs
:
grep 'pattern' input | xargs -I% cp "%" "%.bac"
这篇关于如何将命令输出作为多个参数传递给另一个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文