using a bash variable inside expect

Viewed 31

I have a file called profiles.txt and each line contains a number i.e

11
24
35
46

Using the below script I read the file and store each line as a variable the issue i'm having is that i'm unable to use this variable in the expect part. Is there a way to do it all in expect?

while IFS= read -r line; do
  printf -v "profile$((i++))" '%s' "$line"
done < profiles.txt

/usr/bin/expect <(cat << EOF

spawn telnet 0.0.0.0
send -- "$profile1\r"
send -- "exit\r"
EOF
)````
1 Answers

Move the expect inside the while:

while IFS= read -r line; do
    /usr/bin/expect <(cat << EOF
        spawn telnet 0.0.0.0
        send -- "$line\r"
        send -- "exit\r"
EOF
)
done < /tmp/input
Related