Replacing a string with the contents of a variable using sed by enclosing the search expression with double (") instead of single (') quotes is well documented.
$ astring="Liftoff in [sec]"
$ for s in 3 2 1; do echo $astring | sed -e "s/\[sec\]/$s/"; done
Liftoff in 3
Liftoff in 2
Liftoff in 1
However, how do I conduct the above replacement if the variable content starts with special characters? For example, the variable contents could start with a period forwardslash (./), which is often the case if local file paths are passed as variables?
for s in ./3 ./2 ./1; do echo $astring | sed -e "s/\[sec\]/$s/"; done
sed: -e expression #1, char 14: unknown option to `s'
sed: -e expression #1, char 14: unknown option to `s'
sed: -e expression #1, char 14: unknown option to `s'