Bash – Execute a Command Once Per Line of Piped Input

bashfishshell

I want to run a java command once for every match of ls | grep pattern -. In this case, I think I could do find pattern -exec java MyProg '{}' \; but I'm curious about the general case – is there an easy way to say "run a command once for every line of standard input"? (In fish or bash.)

Best Answer

That's what xargs does.

... | xargs command