How do I fix a "syntax error near unexpected token `('" when using '!(...)' in Makefile?
bash, makefile, shell, syntax, wildcard
Solution
The `!(...)` wildcard syntax only works if the `extglob` shell option is set (`shopt -s extglob`). This option is not enabled by default.
An alternative way to do this is:
find '(' -name .git -o -name folder1 -o -name folder2 ')' -prune -o -exec rm -rf {} \;
Problem
I have a `Makefile` as follows: ``` test: rm -rf !(.git|folder1|folder2) ``` Upon running `make test`, everything in the folder must get deleted except for `.git/`, `folder1/`, and `folder2/`. Instead, I get the following error: ``` /bin/bash: -c: line 0: syntax error near unexpected token `(' /bin/bash: -c: line 0: `rm -rf !(.git|folder1|folder2)' make: *** [test] Error 2 ``` How do I fix this?