I'm using expect
inside my bash script by using expect -c
, but how do I pass parameters to it?
This is what I've tried:
FILE="myFile"
HOST="myhostname"
/usr/bin/expect -c $FILE $HOST '
set FILE [lindex $argv 0];
set HOST [lindex $argv 1];
send_user "$FILE $HOST"
spawn scp -r -o StrictHostKeyChecking=no $FILE root@$HOST:/tmp/
expect "assword:"
send "password\r"
interact'
If I create a separate expect script with the same contents but call it in bash like this:
myScript.expect $FILE $HOST
It works, but how do I do the same thing but using the expect -c
option?
Update:
Also tried:
/usr/bin/expect -c '
set FILE [lindex $argv 0];
set HOST [lindex $argv 1];
send_user "$FILE $HOST"
spawn scp -r -o StrictHostKeyChecking=no $FILE root@$HOST:/tmp/
expect "assword:"
send "password\r"
interact' $FILE $HOST
can't read "argv": no such variable
:( – Katie Mar 02 '18 at 01:16$FILE
and$HOST
won't expand in it. – muru Mar 02 '18 at 01:37