Čamo
Čamo

Reputation: 4170

Shell script error - bad substitution - principle

I am new in shell scripting and all questions I found about this was so complicated that I decided to ask the question about the principle of this error. I have a test.sh file which looks like:

var1="I love Suzi Suzi and Marry"
var2="Sara"
echo "${var1//Suzi/$var2}"

if I run it in terminal via sh test.sh I am getting this error - Bad substitution. Can somebody tell me please what is wrong with it? Thank you.

Upvotes: 0

Views: 925

Answers (1)

Shawn
Shawn

Reputation: 52409

If I run it in terminal via sh test.sh

There's your problem. ${parameter/pattern/string} is bash syntax, not vanilla sh. Run it via bash test.sh (And/or put an appropriate shebang in your script and make it executable so you can just run ./test.sh).

Upvotes: 1

Related Questions