期待脚本采取用户提示

时间:2017-12-04 05:39:40

标签: shell expect

以下是我的样本预期脚本。

#!/usr/bin/expect

set pem [lindex $argv 2]
puts -nonewline "do you want to take histogram\r"
flush stdout
gets stdin pem
if { $pem == "y" } {
    send "./statsCollector.sh\r"
} else {
    puts "aborting\r"
}
expect " bin\]\$ "

我需要用户提示,例如是,Y或y来运行我的脚本(即statsCollector.sh)。如果用户输入其他类似的内容,那么“中止”应该是窗口上的消息。

此处用户输入无法正常工作,中止后也会挂起相同的消息。如果我在这里做错了,请纠正我。

1 个答案:

答案 0 :(得分:0)

我会用这个:

if {[string match {y*} [string tolower [string trimleft $pem]]]} {...

删除前导空格,如果第一个字符是“y”不区分大小写,则...执行操作

参考:https://tcl.tk/man/tcl8.6/TclCmd/string.htm