开发者

is there pipe map in bash? [closed]

开发者 https://www.devze.com 2023-02-19 15:17 出处:网络
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. 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

精彩评论

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