Problem in expect script with password involving trailing backslash

Hi all,
I have wriiten an expect script that genearates a public private key pair through ssh-keygen and then copies that key to the authorized keys file of the remote system . The problem i am facing is when i get a password for the remote machine containg a trailing backslash , the send command in expect fails to perform its function.
The expect script is as follows :
NOTE : I am passing the credentials such as password , username etc. through commandline, The password is the 5th command line argument to the script

#! /bin/sh
set $*
EXPECT_BIN=`which expect`
$EXPECT_BIN <<EOF
set timeout -1
spawn ssh-keygen -t dsa 
expect "Enter file in which to save the key (/root/.ssh/id_dsa):"
send "$KEY_FILE_PATH\r"
expect "/root/.ssh/id_dsa already exists."
expect "Overwrite (y/n)?"
send "y\r"
expect "Enter passphrase (empty for no passphrase):"
send "$PASS_PHRASE\r"
expect "Enter same passphrase again:"
send "$PASS_PHRASE\r"
expect ">"
spawn $7 $6 $3 $4
expect "$3@$4's password:"
send "$5\r"
expect ">"
send "bye\r"
EOF

I would be glad if i can get a solution for this as soon as possible
Thanks

If I'm understanding correctly you are having problems when the password contains a '\' on the end. (i.e. 'abc123\')

If this is the case, the shell is probably seeing this as a line continuation character. You will need to either escape or quote the string. Try something like abc123\\. This will tell the shell to ignore the special meaning of the slash.

Hope this helps.

-B

hi,
I am already doing that before passing the password to the shell script
I even see the correct password when i try printing it in the shell script ie. with the '\'

Or you may try to rewrite it all in tcl inside an expect script without a shell here document where you'll be passing arguments to the expect script directly.
Anyway, some operating systems may have problems accepting passwords with pathological characters
(I remember to have had problems with using a password with embedded # character on HP-UX).

I can try that , Any other solution that sticks to expect in a shell script?