[英]How do I run sed in TCL
I am trying to use TCLs builtin exec
procedure to run the following sed
shell command:我正在尝试使用 TCL 内置
exec
过程来运行以下sed
shell 命令:
sed -i 's/"VALUE.${name}">.*</"VALUE.${name}">${value}</' ${dir}/imp.xml
However when I pass it to exec tcl errors out with但是,当我将它传递给 exec tcl 时出现错误
sed: -e expression #1, char 1: unknown command: `''
no idea how to interpret this.不知道如何解释这个。
I tried escaping the exec string:我尝试了 escaping 执行字符串:
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.然而,这会阻止 tcl 变量在字符串内部展开。
Does anyone know what I need to do to get tcl to exec this sed program?有谁知道我需要做什么才能让 tcl 执行这个 sed 程序?
(my shell is csh if that is relevant) (如果相关的话,我的 shell 是 csh)
The final solution involved 2 changes to the command string,最终解决方案涉及对命令字符串的 2 处更改,
The final, working command string:最终的工作命令字符串:
exec sed -i "s/\"VALUE.${name}\">.*</\"VALUE.${name}\">${alue}</" ${dir}/impl.xml
Each argument to the exec
command must correspond to an individual argument at the shell command line, so enclosing everything in {} doesn't work. exec
命令的每个参数都必须对应于 shell 命令行中的一个单独参数,因此将所有内容包含在 {} 中是行不通的。
Try this:, where all double quotes and dollar signs are escaped.试试这个:,所有双引号和美元符号都被转义了。
exec sed -i 's/\"VALUE.\${name}\">.*</\"VALUE.\${name}\">\${value}' \${dir}/impl.xml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.