sed: unterminated `s' command - Can't figure out what needs to be escaped sed: unterminated `s' command - Can't figure out what needs to be escaped docker docker

sed: unterminated `s' command - Can't figure out what needs to be escaped


Both the sed command and the env var contents need escaping.

sed -i "s/{\\\$PROC_MODCONF}/$PROC_MODCONF/g" /etc/procdev/conf.d/modules.cfg.lua

The sed command is in double quotes. That way bash evaluates the env vars in the double quoted string. So the second $PROC_MODCONF will be replaced with its value from the bash environment.

We need to escape the first literal {$PROC_MODCONF} so that bash does not replace it with the value from the environment.

Since the value of $PROC_MODCONF will be placed into the sed command verbatim, that also needs to be escaped.

$ export PROC_MODCONF="Include\\ \"conf.d\/modconf.cfg.lua\""$ echo $PROC_MODCONFInclude\ "conf.d\/modconf.cfg.lua"


You need to quote the replacement expansions. You need to do that since they contain spaces. $ also needs to be escaped since it's a meta-character.

sed -i s/'{\$PROC_MODULES}'/"$PROC_MODULES"/g /etc/procdev/conf.d/modules.cfg.luased -i s/'{\$PROC_MODCONF}'/"$PROC_MODCONF"/g /etc/procdev/proc.cfg.lua

I might write it with one set of quotes:

sed -i "s/{\\\$PROC_MODULES}/$PROC_MODULES/g" /etc/procdev/conf.d/modules.cfg.luased -i "s/{\\\$PROC_MODCONF}/$PROC_MODCONF/g" /etc/procdev/proc.cfg.lua