4 ms·
Note this string replacement is not anchored (right?) which can end up biting you badly (depending on circumstances of course).
by xolox 2y ago
Note this string replacement is not anchored (right?) which can end up biting you badly (depending on circumstances of course).
- chuckadams 2y agoIt's anchored on the left. ${name#subdir/} will turn 'subdir/abc' into 'abc', but will not touch foo/subdir/bar. I don't think bash even has syntax to replace in the middle of an expansion, I always pull out sed for that.
- xolox 2y agoThanks for clarifying, I learned something new today! Edit: It turns out that Bash does substitutions in the middle of strings using the ${string/substring/replacement} and ${string//substring/replacement} syntax, for more details see https://tldp.org/LDP/abs/html/string-manipulation.html https://tldp.org/LDP/abs/html/string-manipulation.html