【发布时间】:2011-08-09 20:21:27
【问题描述】:
我在 bash 中使用期望。我希望我的脚本 telnet 进入一个盒子,期待一个提示,发送一个命令。如果现在有不同的提示,它必须继续,否则它必须再次发送该命令。 我的脚本是这样的:
\#!bin/bash
//I am filling up IP and PORT1 here
expect -c "
set timeout -1
spawn telnet $IP $PORT1
sleep 1
send \"\r\"
send \"\r\"
set temp 1
while( $temp == 1){
expect {
Prompt1 { send \"command\" }
Prompt2 {send \"Yes\"; set done 0}
}
}
"
输出:
invalid command name "while("
while executing
"while( == 1){"
请帮助我。
我试着把它改成while [ $temp == 1] {
我仍然面临以下错误:
输出:
invalid command name "=="
while executing
"== 1"
invoked from within
"while [ == 1] {
expect {
【问题讨论】:
-
您可能希望在调试此问题时首先编写一个纯期望脚本,这样您就没有可能以微妙方式改变您的期望脚本的 shell 引用规则。
-
看起来很奇怪的错误是怎么回事:因为你的脚本是双引号的,所以 shell(不期望)用空值替换
$temp。
标签: bash while-loop expect