I have a need for recursively looking through a directory and pass all files with a certain extension to a script. In addition it also takes some optional command lines arguments from the user. To put it all together, I did this
usage="blah" while [ "$1" != "" ]; do case $1 in -arg1 ) shift arg1=$1 ;; -arg2 ) shift arg2=$1 ;; * ) echo $usage exit 1 esac shift done find . -name "*.ext" -exec bash -c 'command "$0" arg1="${arg1:-default}" arg2=${arg2:-default}' "{}" \+ However this runs the 'command' command and only passes one file in. How do I get to send the list of files as an argument as well as keep the command line arguments?
EDIT: The command should run only once for the list of matched files.
{}infind ... -exec ... {} +is only needed for zsh, and the+doesn't need to be quoted at all."$@"and- {}do what you want? Does argument order between thefind-provided arguments andarg1/arg2matter?commandis an actual shell builtin, so when you use it, folks have to figure out from context whether you actually meancommandor if it's a placeholder. Consider something likemycommandoryourcommandin examples instead.