Bash: extended regex pattern 'NOT' disabled inside parameter expansion?
I wouldn't wish to keep up my bash saga here. But web seems empty on this.
I just found that some of the extended features of pathname expansions (those that get activated by the shell built-in shopt -s extglob) don't work when the regex pattern is integrated into parameter expansions, but they do work singularly on paths, as they are meanly meant for. Namely, I tested for the 'NOT' operator !(). On path names, I experience correct behaviours: Code:
$ shopt -s extglob Code:
$ shopt -s extglob Also, I think this time The Manual is by my side :) Quote:
|
The difference is caused by the pattern matching in ls !(*meta) operating on each file individually whereas ${x//!(*meta)/} operates on the whole string.
The first match for !(*meta) is "full.jpg full.jpg.meta half.jpg half.jpg.met". This is removed leaving "a" which also matches !(*meta) so is removed as the second match: Code:
c@CW8:/tmp/try$ echo _${x/!(*meta)/}_ Code:
c@CW8:/tmp/try$ ls Code:
c@CW8:/tmp/try$ x=$(ls -x) Code:
c@CW8:/tmp/try$ x=$(/bin/ls -1) |
Quote:
Quote:
|
No secret web page -- just curiosity and experimentation, seasoned with a dash of experience.
Rather than your concept of "match *meta and discard it from the match", my concept is "match the longest string that does not match *meta". Both are reasonable concepts of how things might work but experimentation on bash shows it behaving according to the latter. |
Thank you catkin.
|
All times are GMT -5. The time now is 01:33 PM. |