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 cleanup
):
#!/bin/bash
rm -r !("myfile")
I get:
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.
Notes:
- 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.
{}
button in the formatting menu. Keep use of backticks forinline code
and you'll be fine. – Chris Davies Sep 08 '18 at 09:43