Problem
Behavior
!(pattern-list)
does not work as I would expect when using a parameter in an extension, in particular
${parameter/pattern/string}
Enter
a="1 2 3 4 5 6 7 8 9 10"
Control cases
$ printf "%s\n" "${a/!([0-9])/}"
[blank]
$ printf "%s\n" "${a/!(2)/}"
[blank]
$ printf "%s\n" "${a/!(*2*)/}"
2 3 4 5 6 7 8 9 10
$ printf "%s\n" "${a/!(*2*)/,}"
,2 3 4 5 6 7 8 9 10
$ printf "%s\n" "${a//!(*2*)/}"
2
$ printf "%s\n" "${a//!(*2*)/,}"
,,2,
the functions
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
Notes
These are very simple examples, so if more complex examples with explanations can be included in the answer, please do so.
For more information or examples I need, let me know in the comments.
Have you already seen How extglob works with shell parameter extension? and even commented that the problem is with this particular problem, so please do not mark it as a hoax.
source
share