You probably need to explicitly enable extended patterns in your script:
shopt -s extglob
Question
I'm writing a script that needs to erase everything from a directory except two directories, mysql and temp.
I asked a question earlier and got this code that works in the command line:
rm -rf !(mysql|temp)
However it doesn't work in the script. I get this error "Syntax error: "(" unexpected".
Is there something special about parentheses I need to do?
Solution
You probably need to explicitly enable extended patterns in your script:
shopt -s extglob