Tcl 除了脚本,if的两个分支都不会执行
有人能看一下下面的代码段为什么不执行if语句的两个分支吗?脚本不会抛出任何错误。它只是到达expect行并等待它超时。 arg1只是命令行中的一个参数Tcl 除了脚本,if的两个分支都不会执行,tcl,expect,Tcl,Expect,有人能看一下下面的代码段为什么不执行if语句的两个分支吗?脚本不会抛出任何错误。它只是到达expect行并等待它超时。 arg1只是命令行中的一个参数 set arg1 [lindex $argv 0] set strname "teststring" expect { "prompt#" { if { [string compare $arg1 $strname] != 0 } {
set arg1 [lindex $argv 0]
set strname "teststring"
expect {
"prompt#" {
if { [string compare $arg1 $strname] != 0 } {
send "strings different\r"
} else {
send "strings same\r"
}
}
default abort
}
提前谢谢
编辑:
编辑以显示正确的结构。您的完整脚本更像这样吗?:
#!/usr/bin/expect -d
set arg1 [lindex $argv 0]
set strname teststring
expect {
"prompt#"
if { [string compare $arg1 $strname] != 0 }{
send "strings different\r";
}
else{
send "strings same\r";
}
default abort
}
或者你在跑步,期待其他方式?您使用什么参数运行您的脚本expect的确切程度如何?expect是Tcl的扩展,Tcl非常:
好的,问题解决了。这是因为}{after if'd expect(hah!)之间缺少空格,
expect
中的所有动作脚本都在大括号中。我希望它们只是因为转录错误而丢失。我从传递一个参数的bash脚本调用expect脚本。问题是if-else语句的括号之间的间距。
...
# need a space between the end of the condition and the beginning of the true block
if { [string compare $arg1 $strname] != 0 } {
...
# the else keyword needs to be on the same line as the closing bracket of the true block
} else {
...
}