我在bash中使用expect。我想我的脚本telnet到一个盒子,期待一个提示,发送一个命令。如果现在有不同的提示,则必须继续,否则必须再次发送该命令。 我的脚本是这样的:while while loops within expected
\#!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引用规则可能会以微妙的方式改变您期望的脚本。 – 2011-04-20 22:37:19
奇怪的错误发生了什么:因为脚本是双引号的,shell(不期望)用'null'替换'$ temp'。 – 2011-04-21 01:23:58