如何通过Shell脚本中的命令行传递Expect中的参数 [英] How to pass argument in Expect through the command line in a shell script
本文介绍了如何通过Shell脚本中的命令行传递Expect中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过Shell脚本中的命令行在Expect中传递参数.
I am passing argument in Expect through the command line in a shell script.
我尝试过
#!/usr/bin/expect -f
set arg1 [lindex $argv 0]
spawn lockdis -p
expect "password:" {send "$arg1\r"}
expect "password:" {send "$arg1\r"}
expect "$ "
但是它不起作用.我该如何解决?
But it's not working. How can I fix it?
推荐答案
如果您想读取参数,则可以通过以下方式简单实现
If you want to read from arguments, you can achieve this simply by
set username [lindex $argv 0];
set password [lindex $argv 1];
并打印
send_user "$username $password"
该脚本将打印
$ ./test.exp user1 pass1
user1 pass1
您可以使用调试模式
$ ./test.exp -d user1 pass1
这篇关于如何通过Shell脚本中的命令行传递Expect中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文