Shell – How to pipe stdout to another program

gitpipeshellstdout

I'm trying to setup a linter for my code and I only want to lint the coffeescript files that have changed in the current branch. So, I generate the list of files using git:

git diff --name-only develop | grep coffee$

That gives me a nice list of the files I'd like to process but I can't remember how to pipe this to the linting program to actually do the work. Basically I'd like something similar to find's -exec:

find . -name \*.coffee -exec ./node_modules/.bin/coffeelint '{}' \;

Thanks!

Best Answer

Just pipe through a while loop:

git diff --name-only develop | grep coffee$ | while IFS= read -r file; do
    ./node_modules/.bin/coffeelint "$file"
done
Related Question