prodigitalson
prodigitalson

Reputation: 60413

Bash string replacement gives me "bad substitution"

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="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...

Upvotes: 12

Views: 16899

Answers (1)

Gilles Quénot
Gilles Quénot

Reputation: 184955

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

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

Note no $ sigill for URL in ${} =)

Upvotes: 28

Related Questions