On Thu, Feb 20, 2025 at 13:50:29 +0200, Timotei Campian wrote:
> *OS*=debian12
> *BASH_VERSION*="5.2.15(1)-release"
>
> the script test.sh has the following content:
>
> echo !(file.f*)
>
>
> Now calling bash pretty-print result in this error:
>
> *bash --pretty-print test.sh*
>
> file1: line 2: syntax error near unexpected token `('
> file1: line 2: `echo !(file.f*)'
You're using an extended glob, but you haven't enabled it within the
script. You'll need to run "shopt -s extglob" somewhere in the script
before that line is read by the parser. (In other words, if this
echo command is inside a function, the shopt must be executed before
the function is parsed -- not just before the function is called.)
Simplest:
#!/bin/bash
shopt -s extglob
echo !(file.f*)
This one will NOT work:
#!/bin/bash
f() {
shopt -s extglob
echo !(file.f*)
}
f
This one will work:
#!/bin/bash
shopt -s extglob
f() {
echo !(file.f*)
}
f