is there pipe map in bash? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years 开发者_如何学Pythonago.
Improve this questioncmd1 | 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
精彩评论