Bash 字符串替换给了我“坏替换”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15116427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:41:27  来源:igfitidea点击:

Bash string replacement gives me "bad substitution"

bashreplace

提问by prodigitalson

I have a variable that is a url and i want to replace part of that url in bash, but i keep getting "bad substitution"

我有一个 url 变量,我想在 bash 中替换该 url 的一部分,但我不断收到“错误替换”

URL="http://hostname/project/branches/Old_Branch/package"
SRC="Old_Branch"
REP="New_Branch"

echo ${$URL/$SRC/$REP};
# desired output is http://hostname/project/branches/New_Branch/package

Not sure exactly where I'm going wrong...

不知道我到底哪里错了......

回答by Gilles Quenot

URL="http://hostname/project/branches/Old_Branch/package"
SRC="Old_Branch"
REP="New_Branch"

echo "${URL/$SRC/$REP}"

Note no $sigill for URLin ${}=)

注意没有$符号URLin ${}=)