1
我希望以下期望腳本在主bash腳本中設置變量。換句話說,我想將$ SSH_SUCCESS設置爲合格/不合格字符串。我曾嘗試使用$ expect_out和$ :: env(SSH_SUCCESS),但未成功。我如何設置一個bash變量來期望?如何獲得期望設置bash變量
expect << EOF
log_user 0
log_file $TEST_LOG
set timeout 5
spawn ssh [email protected]$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
腳本無法在另一個進程中設置變量。該腳本應該輸出結果,並且父腳本應該用'$(...)'來捕獲它。 – Barmar
夠公平的。我將如何在條件語句中準備一個「標誌」,以及如何在父腳本中讀取它? – AFridgeTooFar