标签:条件语句 信息 dea $2 expect 输入 shell脚本 set 特殊
[root@xt expects]# cat var.exp
#!/usr/bin/expect
set passwd "1234"
puts $passwd
send_user "$passwd\n"
[root@xt expects]# expect var.exp
1234
1234
[root@xt expects]#
[root@xt expects]# cat canshu.exp
#!/usr/bin/expect
set name [lindex $argv 0]
set home [lindex $argv 1]
set age [lindex $argv 2]
puts "$name\t$home\t$age"
puts "$argc"
send_user "$argv0 [lrange $argv 0 2]\n"
[root@xt expects]# expect canshu.exp xuetong gx 18
xuetong gx 18
3
canshu.exp xuetong gx 18
[root@xt expects]#
执行脚本时必须要输入参数,没提示判断输入参数功能。可以通过if语句实现
if {$argc != 3} {
send_user "usage:expect $argv0 name home age\n"
exit
}
#!/usr/bin/expect
if {$argc < 10} {
puts "error idea!"
} else {
puts "bingo !"
}
标签:条件语句 信息 dea $2 expect 输入 shell脚本 set 特殊
原文地址:http://blog.51cto.com/12580678/2349278