Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash string replacement gives me "bad substitution"

Tags:

bash

replace

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

like image 741
prodigitalson Avatar asked Feb 27 '13 15:02

prodigitalson


1 Answers

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

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

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

like image 58
Gilles Quenot Avatar answered Nov 11 '22 14:11

Gilles Quenot