8

我有一个 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

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

4

1 回答 1

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

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

请注意in =)中没有$标记URL${}

于 2013-02-27T15:57:24.477 回答