Find (and any other command) needs to see all its params as distinct words.
let's see what find gets from your expansion
Code:
find_params=( -iname "*.java" -o -iname "*.h" -iname "*.sh" )
$ i=0; for x in "\( ${find_params[@]} \)"; do echo $((++i)) \'"$x"\'; done
1 '\( -iname'
2 '*.java'
3 '-o'
4 '-iname'
5 '*.h'
6 '-iname'
7 '*.sh \)'
$ i=0; for x in "(" "${find_params[@]}" ")"; do echo $((++i)) \'"$x"\'; done
1 '('
2 '-iname'
3 '*.java'
4 '-o'
5 '-iname'
6 '*.h'
7 '-iname'
8 '*.sh'
9 ')'
as you can see you shouldn't glue quoted params array with anything else otherwise you will merge things together.
that
\( you often see in examples of find is equivalent to
"(" or
'('. It's escaped because by default bash recognizes ( and ) as syntax related and you need to make it ignore them.
You pick one of these forms and you need to make sure it's a standalone parameter.
you can write all commands in this form
Code:
some_command '(' 'param1' '-o' 'param2' ')'
but since bash can figure out what is a word we don't have to do all that quoting, unless it has some char(s) that can break things like space,tab,;,*,?,(,) etc.
Bookmarks