Search This Blog


Escaping Special Characters in tcl

In some cases different interpreters will not perform the action you expect.

In the case below, I wanted to execute a bash function called from tcl

set variable [exec who | awk '{print $1}']

So I figured, oh i'll just escape the $ with a \

set variable [exec who | awk '{print \$1}']

Didn't work. How about I escape the escape?

set variable [exec who | awk '{print \\$1}']

Still no good.

It turns out that bash uses the '{' and '}' in order to say "do not interpret this".

So the following works for my uses:

set variable [exec who | awk {{print $1}}]


No comments:

Post a Comment