bash file globbing anomaly -
the bash manual (i'm using version 4.3.42 on osx) states vertical bar '|' character used separator multiple file patterns in file globbing. thus, following should work on system:
projectfiles=./config/**/*|./support/**/* however, second pattern gives "permission denied" on last file in directory structure pattern never resolved projectfiles. i've tried variations on this, including wrapping patterns in parentheses,
projectfiles=(./config/**/*)|(./support/**/*) which laid out in manual, doesn't work either.
any suggestions on i'm doing wrong?
you're referring part in man bash:
if extglob shell option enabled using shopt builtin, several extended pattern matching operators recognized. in following description, pattern-list list of 1 or more patterns separated |. composite patterns may formed using 1 or more of fol- lowing sub-patterns: ?(pattern-list) matches 0 or 1 occurrence of given patterns *(pattern-list) matches 0 or more occurrences of given patterns +(pattern-list) matches 1 or more occurrences of given patterns @(pattern-list) matches 1 of given patterns !(pattern-list) matches except 1 of given patterns
the | separator works in pattern-lists explained, when extglob enabled:
shopt -s extglob try this:
projectfiles=*(./config/**/*|./support/**/*) as @broslow pointed out in comment:
note can without
extglob,./{config,support}/**/*, expand path config , path support space delimited , pattern matching. or./@(config|support)/**/*extglob. either of seems cleaner.
@chepner's comment worth mentioning:
also, globbing isn't performed @ during simple assignment; try
foo=*, compareecho "$foo"echo $foo. globbing occur during array assignment; seefoo=(*); echo "${foo[@]}"
Comments
Post a Comment