Search code examples
stringsedescapingtclcsh

How do I run sed in TCL


I am trying to use TCLs builtin exec procedure to run the following sed shell command:

sed -i 's/"VALUE.${name}">.*</"VALUE.${name}">${value}</' ${dir}/imp.xml

However when I pass it to exec tcl errors out with

sed: -e expression #1, char 1: unknown command: `''

no idea how to interpret this.

I tried escaping the exec string:

exec {sed -i 's/"VALUE.${name}">.*</"VALUE.${name}">${value}</' ${dir}/imp.xml}

However this prevents the tcl variables from being expanded inside of the string.

Does anyone know what I need to do to get tcl to exec this sed program?

(my shell is csh if that is relevant)


Solution

  • The final solution involved 2 changes to the command string,

    1. Escape all the double quote characters, (thanks @Chris Heithoff)
    2. Single quotes are handled funny by TCL, replacing them with double quotes (that are not escaped!) resolves the issue.

    The final, working command string:

    exec sed -i "s/\"VALUE.${name}\">.*</\"VALUE.${name}\">${alue}</" ${dir}/impl.xml