I am practicing with parameter substitution on bashin bash.
I wrote the following dummydummy script:
#!/bin/bash var1="/some/path/to/file/the_file.arbitrary.n.ext.0.random.ext" var2="/some/path/to/file/the_file.arbitrary.n.ext.0.ext" pattern='.[0-9]?(.random).ext' echo "${pattern}" echo "${var1/${pattern}/}" echo "${var2/${pattern}/}" Basically, the patternpattern is meant to stripstrip off the last part of the file name.
The execution of dummyExecuting the dummy script results in:
~$ ./dummy.sh .[0-9]?(.random).ext /some/path/to/file/the_file.arbitrary.n.ext.0.random.ext /some/path/to/file/the_file.arbitrary.n.ext.0.ext whereas the eval of dummyevaling the script's contents or, equivalently, the direct input of that sequence of commands in the interactive shellinteractive shell, results in:
~$ eval "$(cat dummy.sh)" .[0-9]?(.random).ext /some/path/to/file/the_file.arbitrary.n.ext /some/path/to/file/the_file.arbitrary.n.ext The patternpattern '.[0-9]*.ext' works, so the issue clearly is confined into the sub-string '?(.random)'. The issue could be with ?, since it is a reserved keyreserved character in the context of parameter substitutionparameter substitution. However, if that waswere the issue, I would expect the patternpattern to either fail or succeed the same in both cases.
Where's the probably obviousprobably obvious pitfall?