Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
3 deleted 4 characters in body; edited tags; edited title
source | link

Syntax error near unexpected token `!(' inside*.sh) works on the command line but not in a script

When I use belowthe code below in Ubuntua terminal on Ubuntu, it works fine:

rm !(*.sh) -rf

But if I place the same line code in a shell script (clean.shclean.sh) and run shell script from terminal, it throws error as this

clean.sh script:

#!/bin/bash
rm !(*.sh) -rf

error iError I get:

./clean.sh: line 2: syntax error near unexpected token `('
./clean.sh: line 2: `rm !(*.sh) -rf'

can you help?

Thanks, Tal.

Syntax error near unexpected token `(' inside script

When I use below code in Ubuntu terminal, it works fine:

rm !(*.sh) -rf

But if I place the same line code in a shell script (clean.sh) and run shell script from terminal, it throws error as this

clean.sh script:

#!/bin/bash
rm !(*.sh) -rf

error i get:

./clean.sh: line 2: syntax error near unexpected token `('
./clean.sh: line 2: `rm !(*.sh) -rf'

can you help?

Thanks, Tal.

!(*.sh) works on the command line but not in a script

When I use the code below in a terminal on Ubuntu, it works fine:

rm !(*.sh) -rf

But if I place the same line code in a shell script (clean.sh) and run shell script from terminal, it throws error as this

clean.sh script:

#!/bin/bash
rm !(*.sh) -rf

Error I get:

./clean.sh: line 2: syntax error near unexpected token `('
./clean.sh: line 2: `rm !(*.sh) -rf'

can you help?

2 Add the wildcards tag
| link
1
source | link

Syntax error near unexpected token `(' inside script

When I use below code in Ubuntu terminal, it works fine:

rm !(*.sh) -rf

But if I place the same line code in a shell script (clean.sh) and run shell script from terminal, it throws error as this

clean.sh script:

#!/bin/bash
rm !(*.sh) -rf

error i get:

./clean.sh: line 2: syntax error near unexpected token `('
./clean.sh: line 2: `rm !(*.sh) -rf'

can you help?

Thanks, Tal.