Home > Enterprise >  Multiple commands with xargs with batch load
Multiple commands with xargs with batch load

Time:07-19

I am trying to run xargs on multiple files at once:

sh -c 'find . -name "*.py" | xargs pylint'

This will give me a single pylint score for all py files in a repo. However when I try to modify it to do both black and pylint, it loops through each file individually and gives me the pylint score and black diff on each file:

find . -name "*.py" | xargs -I % sh -c 'pylint %; black --check --diff %;'

Any way to pass in the py files in batch rather than each individually?

CodePudding user response:

If you use -I option it runs given command once for each entry in input.

You can do this instead:

find . -name "*.py" |
xargs sh -c 'pylint "$@"; black --check --diff "$@"'
  • Related