Sed variable not expanding

I have also some difficulty calling sed to change a word in a file.

sed -i 's/docTitl/Outline ${docTitl}/g' $ofln

You need to use double quotes, rather than single ones in this case. Shell variables inside single quotes do not get expanded.

1 Like

Have noticed that using double quotes solves the problems.

sed -i "s/docTitl/Outline ${docTitl}/g" $ofln

Hi
It's best to do so.
Take a variable in double quotes
and enclose the left and right parts of the script body
single quotes

's/docTitl/Outline '     "$docTitl"    '/g'

it turns out such a design

sed -i 's/docTitl/Outline '"$docTitl"'/g' $ofln