SED in TCL/TK and any other equivalent command in TCL

人走茶凉 提交于 2019-12-25 03:48:42

问题


I am trying pass value from TK to cshell script using "procedure call" now.... as follow.

proc Run {} {
   global passedvalue
   ## to see what value it has for passedvalue
   puts  $passedvalue  
   exec sed -i {s/ABC/$passedvalue/g} runme.sh
   exec /bin/csh -c ./runme.sh >@stdout 2>@stderr
}   

I am changing a line which has value ABC by new passedvalue. "puts" works and prints the value of passedvalue properly. But it does not work for sed and it gives

Error : Program undefined variable

Please let me know how where I am doing wrong.

I have tried using string map as well but did work either...I might be doing something wrong.


回答1:


Curly braces inhibit variable substitution. If you want $passedvalue to be expanded before calling exec, you'll need to use some other quoting mechanism.

For example, you could use double quotes:

exec sed -i "s/ABC/$passedvalue/g" runme.sh

You will need to add some extra bullet-proofing, however. For example, if $passedvalue Has a / in it, you will send a mal-formed expression to sed.



来源:https://stackoverflow.com/questions/25048523/sed-in-tcl-tk-and-any-other-equivalent-command-in-tcl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!