如何通过参数通过在shell脚本的命令行预期 [英] How to pass argument in expect through command line in shell script
本文介绍了如何通过参数通过在shell脚本的命令行预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我传递的参数在期望
通过命令行shell脚本
I am passing argument in expect
through command line in 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. Please help me to figure it out.
感谢
推荐答案
如果你想从参数看,你可以简单地
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脚本的命令行预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文