A
A
alienstone2016-04-22 20:05:48
linux
alienstone, 2016-04-22 20:05:48

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

2 answer(s)
V
viiy, 2016-04-22
@alienstone

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

This is an abstract way, adapt the arguments to suit your needs.

A
alegzz, 2016-04-22
@alegzz

Push arguments into a variable?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question