0

My script parameters on the mask and consist parameters for the find tool:

$mopt=false
case $1 in
...
    -m|--mask-file)     
            if $mopt; then
                or="-o"
            fi       
            mask+=("$or -name $2 ")
            mopt=true
            shift 2;;
...


find . "${mask[@]}"
=>
+ find . '-name *.cpp -o -name *.txt'

Although not expand, but fails because the apostrophes around all parameters. When the $mask has quotes expands.

If I add quotes already hard at creating parameters for the find tool:

$mask+=("$or -name \"$2\" ")
find . {$mask[@]}
=>
+ find . -name '"*.cpp"' -o -name '"*.txt"'

-name '' * .cpp '' -o -name '"* .txt"'

Find tool is performed with double quotation marks around the mask and also fails. If you write a script to manually into script:

find . -name "${mask[0]}" -o -name "${mask[1]}"...

command is executed correctly, but I need to create a name for the find parameters automatically, so that you can enter a variable number of masks. How, then find stack the order can be entered:

find . $mask ...
  • Are you asking how to prevent expansion of *.txt into a list of files? If so, quote: '*.txt'. If not, please edit your question to clarify; as it is, I have a very hard time understanding what you are asking. – dhag May 5 '15 at 14:46
  • Question is changed. – user113201 May 6 '15 at 10:34
2

You want it to be 2 or 3 arguments to find: ("-o"), "-name" and "$2", so that's:

mopt=false
case $1 in
...
    -m|--mask-file)     
            "$mopt" || mask+=(-o)
            mask+=(-name "$2")
            mopt=true
            shift 2;;

find . "${mask[@]}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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