Answer the question
In order to leave comments, you need to log in
How to run variadic utility from bash?
Good afternoon
I am writing a wrapper over find. I make a list of "include" and "exclude" paths (we check and exclude accordingly).
The input to my script is a list of keys -i path1 -i path2 ( -e path1 -e path2 )
Accordingly, I want to run find . -path 'path1' -prune -o -path 'path2' -prune -o -print
But I don't know how to make find be called each time with a different number of arguments
Please help me solve this problem
Thank you
Answer the question
In order to leave comments, you need to log in
The most convenient way is through getopts
FINDOPTS=''
while getopts "i:e:" opt; do
case $opt in
e) FINDOPTS=$FINDOPTS" --exclude $OPTARG ";;
i) FINDOPTS=$FINDOPTS" --include $OPTARG ";;
esac
done
echo $FINDOPTS
$ ./getopts.sh -i path1 -i path2 -i path3 -e path4 -e path5
--include path1 --include path2 --include path3 --exclude path4 --exclude path5
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question