I have a bash script which calls the 'find' command with multiple directories to prune.
Here is the entire script:
PRED="-wholename '$SRCDIR/skip1' -o -wholename '$SRCDIR/skip2'"
echo find $SRCDIR '\(' $PRED '\)' -prune -or -print
find $SRCDIR '(' $PRED ')' -prune -or -print
I have under SRCDIR the directories skip1, skip2, look1, and look2, each with a few files in it.
If I run the script and paste the echoed line into the bash prompt, it will print out:
I understand that the parentheses \( and \) need to be escaped to protect them from the shell, and this is the result I want.
I want the next line in the script to do the exact same thing, but called from the script. But the result is :
I can not figure out how to properly escape the parentheses characters within the script. I've tried all sorts of variations instead of '(' and ')', and here are the results:
( ... ) -> bash error: syntax error near unexpected token `('
'\(' ... '\)' -> find error: paths must precede expression
"\(" ... "\)" -> find error: paths must precede expression
\( ... \) -> same as '(' ... ')' , find prints out all directories
How can I properly tell find to treat the parentheses as precedence operators?