I was reviewing this post: Split a string by some separator in bash?
In my scenario, I tried to use just Bash to accomplish this, but I'm running into some weird behavior.
shopt -s extglob
export var=abc_def__123__456
echo ${var/%__*}
echo ${var/#!(__)__}
shopt -u extglob
The first echo is working as expected and outputs abc_def. I'm expecting the second echo to output 123__456 and instead, it outputs 456. This is not working the way I'm reading the manual, which says:
If pattern is preceded by ‘#’ (the third form above), it must match at the beginning of the expanded value of parameter.
To me, this means that when it gets to the first occurrence of __, the match should stop and so the second echo should return 123__456, which is desired.
What am I missing?