getting error while substituting variable using sed..

I am using script for substitute one variable with another variable like below...
below code works fine...

sed 's/'$sub_fun'/'$To_sub'/g'

But when i run the same code from the script getting below errors..

sed: -e expression #1, char 7: unterminated `s' command

please help.... :wall:

That's because either the search string or the replacement string has embedded white spaces and since you've allowed the shell to interpret those white-spaces as word-separators (by not double-quoting the variables), it is breaking the sed command.

Use

sed 's/'"$sub_fun"'/'"$To_sub"'/g'
1 Like

Thanks a lot...:slight_smile:

It is working fine now....