How to use the bash builtin to replace the output of a subshell or function
No, that nesting of substitution operators is unique to zsh
.
Note that with zsh
like with (t)csh
, you can also do ${PWD:t:s/trunk/latest/}
.
Though bash
also supports those csh history modifiers for history expansion, it doesn't support them for its parameter expansions.
Here with bash
, use a temporary variable:
var=${PWD##*/} var=${var//trunk/latest}
Try this with bash:
[[ $PWD =~ .*/(.*) ]] && echo "${BASH_REMATCH[1]//trunk/latest}"
or with one command:
[[ $PWD =~ .*/(.*) && ${BASH_REMATCH[1]//trunk/latest} =~ (.*) ]]
The result is in ${BASH_REMATCH[1]}