bash "map" equivalent: run command on each file

Posted by Claudiu on Stack Overflow See other posts from Stack Overflow or by Claudiu
Published on 2010-04-14T19:25:11Z Indexed on 2010/04/14 19:33 UTC
Read the original article Hit count: 205

Filed under:
|
|
|

I often have a command that processes one file, and I want to run it on every file in a directory. Is there any built-in way to do this?

For example, say I have a program data which outputs an important number about a file:

./data foo
137
./data bar
42

I want to run it on every file in the directory in some manner like this:

map data `ls *`
ls * | map data

to yield output like this:

foo: 137
bar: 42

© Stack Overflow or respective owner

Related posts about bash

Related posts about shell