Shell heredocs are essentially big double-quoted strings. The shell is substituting the $expect_out
variable (with an empty string since the shell session has no such variable) before expect gets launched. You need to single-quote the expect script body to protect the expect variables from the shell, or escape any $
:
expect << 'EOF'
# ........^...^
# everything else is the same
http://www.gnu.org/software/bash/manual/bashref.html#Here-Documents