How to escape Special Characters in Expect programming?

Hi,

I have written a unix expect utility "ssh-login.exp" which connects (ssh) to remote host and execute some shell script. I am calling this "ssh-login.exp" utility from another shell script.

"ssh-login.exp" takes username, password, host and shell script path to execute on remote host. All works fine for alphanumeric password. If password has any special characters like "$" this "ssh-login.exp" doesn't work. I have already added code to add escape character before any special characters password may have.

e.g. for password string "welcome$123" and I send "welcome\$123".

But the problem is, when expect utility "ssh-login.exp" sends password to remote host it prepends '{' and appends '}' to password string if password has any special characters. if password doesn't have any special characters then it sends password without '{' and '}' and works fine.

e.g. for password "welcome$123" expect program sends "{welcome\$123}", in fact it should send "welcome\$123" (without '{' and '}' ) and remote machine don't allow the entry because of wrong password.

So I am trying to find out a way to get rid of '{' and '}' from password string before sending it to remote host in case password has any special characters.

Here is my expect script : "ssh-login.exp":

#!/usr/bin/expect -f

set username [lrange $argv 0 0]
set password [lrange $argv 1 1]
set host [lrange $argv 2 2]
set script [lrange $argv 3 3]

set prompt "*$*"

set scriptIO  [open ./$script r]
set scriptContents [read -nonewline $scriptIO]
close $scriptIO

spawn ssh -q -o StrictHostKeyChecking=no $username@$host

#match_max 100000

while (1) {
        expect {
                "no)? " {
                        send -- "yes\r"
                        send -- "\r"
                }
                "*?assword:*" {
                        send -- "$password\r"
                        send -- "\r"
                }
                "$prompt" {
                        send -- "pwd\r"
                        send -- "\r"
                        break;
                }
        }
}

send -- "\r"

send -- "$scriptContents\r"

send -- "exit\r"

expect eof

Please let me know if someone has already faced this issue and were able to resolve the same.

Thanks,

Any help would be greatly appreciated!