Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running the following bash command:

find . \( -iname '*.aif' -o -iname '*.pdf' -o -iname '*.exe' -o -iname '*.mov' \
    -o -iname '*.doc' \) -exec rm -f {} \;

I'm running the same parameters in another call to find later on in the script. Is there any way to store the \( -iname '*.aif' -o -iname '*.pdf' -o -iname '*.exe' \ -o -iname '*.mov' -o -iname '*.doc' \) part in a variable?

share|improve this question
up vote 2 down vote accepted

In ksh, bash or zsh, use an array variable.

find_parameters=(\( -iname '*.aif' -o … -iname '*.doc' \))
find . "${find_parameters[@]}"

In other shells, there's no good way (there are complex and brittle ways but I don't recommend them unless you really need them). If you need a single array, you can use the positional parameters:

set \( -iname '*.aif' -o … -iname '*.doc' \)
find . "$@"
share|improve this answer
That works fine, thanks. So is that an array containing \(, -iname, '*.aif', -o, -iname, ...? I've just never seen an array definition like that. – Matt Alexander Jan 27 '11 at 20:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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