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 ...
2
  • 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, 2015 at 14:46
  • Question is changed.
    – user113201
    May 6, 2015 at 10:34

1 Answer 1

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[@]}"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .