I'd like to be able to pass in a modified grep command to xargs. I am overriding a command with a function in bash similar to Is it possible to override the command line's built in "cd" command?. My function below works, except when passing to xargs. Why is this and how do I work around this?
redefined:
function grepc() { $(which grep) -c "$@"; }
works:
find -name '*.py' | grepc web
2
xargs fails:
find -name '*.py' | xargs grepc import
xargs: grepc: No such file or directory
(passing to xargs here should grep the file contents of the python list, which is a weird contrived example but the point is xargs can't find grepc)
TLDR: why can't | xargs <function> work? Does <function> actually need to be a <builtin> or something?