expect script with special characters?

Hello all, I'm writing an expect script that will connect to an IMAP server and issue IMAP commands. The problem is that some of the text I need to send includes "quotes" and also !@#$%^&* special characters.

For example, my password is VFR$5tgb but I cannot "send" this because Expect doesn't like the $ symbol.

So

expect "OK"
send "a01 login lupin VFR$5tgb\r"

Does not work, expect thinks the $ is denoting a variable.

Also, I need to send the following IMAP command:

a02 list "" "*"

however it contains quotation marks. So I cannot wrap the whole thing in quotation marks or Expect does not interpret it properly.

expect "a01 OK"
send "a02 list "" "*"\r"

does not work as Expect doesn't parse the quotation marks properly.

I've tried google search but can't find any relevant results.

Any Expect gurus that can point me in the right direction? Thank you

since no other replies yet..

it's been a long time since i've wrote in tcl, but the easiest solution would be to put a backslash before these special characters.
example:

send "a01 login lupin VFR\$5tgb\r"

send "a02 list \"\" \"*\""
1 Like

perfect, that did the trick! thanks. :b: