SED in TCL/TK and any other equivalent command in

2019-09-10 13:14发布

问题:

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.



标签: tcl tk