Francisco Ortiz
Francisco Ortiz

Reputation: 71

Shell script isn't working

I can't find out what's happening. Is this regular expression not working for shell scripts?

sudo rm -R -f '/web/!(release)'

Any ideas?

thanks

Upvotes: 1

Views: 98

Answers (2)

Francisco Ortiz
Francisco Ortiz

Reputation: 71

Script file

shopt -s extglob

sudo rm -R -f 'web/'!(release);

Result

script.sh: Syntax error: "(" unexpected

edit :

I was running with "sh" instead of bash

now with bash script.sh it works

thanks

Upvotes: 1

konsolebox
konsolebox

Reputation: 75458

Perhaps you forgot to enable extglob. Also you shouldn't quote your extended glob pattern:

shopt -s extglob
sudo rm -R -f '/web/'!(release)

Also if the shell you're calling sudo with is not able to access /web, you can wrap up your command with bash:

sudo bash -c "shopt -s extglob"$'\n'"rm -R -f '/web/'!(release)"

See Pattern Matching and Filename Expansion.

Upvotes: 1

Related Questions