我希望以下期望脚本在主 bash 脚本中设置一个变量。换句话说,我想将 $SSH_SUCCESS 设置为通过/失败字符串。我曾尝试使用 $expect_out 和 $::env(SSH_SUCCESS) 但没有成功。如何从期望中设置 bash 变量?
expect << EOF
log_user 0
log_file $TEST_LOG
set timeout 5
spawn ssh root@$RADIO_IP
.....
....expect script, echoing the return of an SSH command...
send "echo\$?\n"
expect {
"0" {
send_user "SSH test: PASSED\r"
SSH_SUCCESS="PASSED"
}
"1" {
send_user "SSH test: FAILED\r"
SSH_SUCCESS="FAILED"
}
sleep 1
send_user "\n"
exit
EOF
echo $SSH_SUCCESS