This question already has an answer here:
If I want to delete everything in the current directory except for "myfile", I can use
rm -r !("myfile")
But if I put this in a script (called
#!/bin/bash rm -r !("myfile")
pi@raspberrypi:~/tmp $ ./cleanup ./cleanup: line 2: syntax error near unexpected token `(' ./cleanup: line 2: `rm -r !("file2")'
If I run
ps -p $$
I can see that my terminal is using bash,
PID TTY TIME CMD 1345 pts/3 00:00:02 bash
so I'm unclear on what the problem is.
- I realize that if the script actually worked, it would delete itself. So, my script really would be something more like:
rm -r !("cleanup"|"myfile"), but the error message is the same either way.
- As shown by the blockquote, this is on a Raspbian OS (9 - stretch), which is Debian based.
- I feel like this question is bound to be a duplicate, but I can't find it. There is a similarly named question, but it is in regards to inheriting variables, and so doesn't address my issue.