I'm trying to replace a substring in $1 with another, AND set it to a variable.

(saved as testStringReplacement file)

myString= "${1/Suzi/$secondString}"
echo "myString = $myString"

Then when I run this:

bash testStringReplacement Suzi

I get this:

testStringReplacement: line 3: Sara: command not found
myString = 

Can anyone see what I'm doing wrong? I want myString to be a string equal to the value of the string substitution (in this case, it should get set to "Sara"). It looks like it's doing the replacement, but trying to then execute it as a command.


1 Answer 1


You have a space after the = in this:

myString= "${1/Suzi/$secondString}"

That will make it be interpreted as setting myString to blank and then try to run the command ${1/Suzi/$secondString}

It should be


Not the answer you're looking for? Browse other questions tagged or ask your own question.