0

I'm using this expect script as an answerfile to a interactive shell script:

#!/usr/bin/expect

spawn ./interactivescriptname
expect "Question 1?"
send "something\r"
expect "Question 2?"
send "yes\r"
expect "Password?"
send "somepassword\r"
interact

above works, but i want to use variables from a inputfile.

my variables files look like this:

var1="something"
var2="yes"
var3="somepassword"

Normally in bash i would use the source command, but this doesn't work in expect.

Any ideas?

0

One method would be to set TCL variables in a file (here, vars) and then source that file from the main script.

$ cat vars  
set var1 something
set var2 yes
set var3 Hunter2
$ cat script 
#!/usr/bin/env expect
source vars
puts $var3
$ chmod +x script
$ ./script 
Hunter2
$ 

It may be good to use more informative variable names than varN ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.