My command: git show --pretty="format:" --name-only returns list of files. Then I use xargs to run a shell script on those files:

git show --pretty="format:" --name-only  | xargs -i phpmd $dir/'{}' text codesize,unusedcode,naming

However, I'd like to run that xargs command only on files with .php extension. How to filter the unwanted files?

link|improve this question

feedback

2 Answers

up vote 2 down vote accepted
... | grep '\.php$' | ...
link|improve this answer
Thank you Ignacio. – takeshin Sep 1 '10 at 11:01
feedback

If your filenames may contain space or quotes, you should use GNU Parallel http://www.gnu.org/software/parallel/ instead of xargs as xargs can lead to nasty surprises because of the separator problem http://en.wikipedia.org/wiki/Xargs#The_separator_problem:

git show --pretty="format:" --name-only  | grep '\.php$' | parallel phpmd $dir/{} text codesize,unusedcode,naming

GNU Watch the intro video for GNU Parallel to learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQ

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.