开发者

is there pipe map in bash? [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 10 years 开发者_如何学Pythonago.

Improve this question
cmd1 | cmd2

will call cmd2 only once with cmd1 output as argument. What i want is call cmd2 one by one with each line of cmd1 output as argument. Maybe something looks like:

cmd1 | map cmd2

I know i can write one by myself, just want to know is there built-in support already?


for i in `cmd1`; do cmd2 $i; done

should do it.


cmd1 | xargs -l cmd2

This is my favorite way. Thanks to Paulo Ebermann!


cmd1 | while read x
do
  cmd2 $x
done


use xargs

cmd1|xargs cmd2

eg:

ls xyz*|xargs grep "abc"

abc will be searched in all the files whose name starts with xyz

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜