2016-02-08 09:00:09 -0500, Chet Ramey: > On 2/8/16 2:47 AM, Linda Walsh wrote: > > When you are doing a var expansion using the > > replacement format ${VAR//./.}, is there some way to > > put parens around some part of the expression and reference > > them as in the [[V~re]] RE-matches? > > No. Shell patterns do not have backreferences. [...]
Note that the feature is available in other shells and quite handy there. It could be worth adding to bash $ zsh -o extendedglob -c 'a=1234; echo ${a//(#b)(?)(?)/${match[2]}${match[1]}}' 2143 (#b) to activate back-references stored in $match array. $ zsh -o extendedglob -c 'a=1234; echo ${a//(#m)?/<$MATCH>}' <1><2><3><4> (#m) to record the matched portion in $MATCH. Though I suspect for bash you would prefer the ksh93 syntax: $ ksh93 -c 'a=1234; echo ${a//@(?)@(?)/\2\1}' 2143 -- Stephane