假设我们声明
test="/this/isjust/atestvariable/for/stringoperation"
Run Code Online (Sandbox Code Playgroud)
我们想用冒号 ':' 替换 '/' 的每个实例。
然后,我认为这个命令应该有效:
echo ${test//\/:}
Run Code Online (Sandbox Code Playgroud)
(as${variable//pattern/string}
用指定的字符串替换模式的所有匹配项)
但是,在运行 echo 时${test//\/:}
,我得到的输出为
/this/isjust/atestvariable/for/stringoperation
Run Code Online (Sandbox Code Playgroud)
我可能哪里出错了?感谢您的帮助。