Expect 文件中的变量
我有一个看起来像这样的期望文件。 来调用脚本。expect文件中是否有变量的概念?
expect myfile.exp
我使用“我希望能够发送 1、2、3 或 4”的值
expect -exact "> "
sleep .1
send -s -- "1\r"
expect -exact "> "
sleep .1
# This prompt can take values 1, 2, 3 or 4
send -s -- "1\r"
# I want to replace "1\r" above with one of the 4 possible values at runtime
expect -exact "> "
sleep .1
send -s -- "1\r"
I have an expect file that looks like this. I invoke the script using
expect myfile.exp
I want to be able to send a value of 1,2,3 or 4. Is there a notion of variable within the expect file?
expect -exact "> "
sleep .1
send -s -- "1\r"
expect -exact "> "
sleep .1
# This prompt can take values 1, 2, 3 or 4
send -s -- "1\r"
# I want to replace "1\r" above with one of the 4 possible values at runtime
expect -exact "> "
sleep .1
send -s -- "1\r"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您希望这是互动的吗?那么脚本请求用户输入还是需要依赖于它收到的某些值?
请求用户输入:
http://my.safaribooksonline.com/book/operating-systems-and-server-administration/unix/9781565920903/handling-a-process-and-a-user/the_expect_user_command
Do you want this to be interactive? So that the script requests input from the user or does it need to be dependant on some value it receives?
Request user input:
http://my.safaribooksonline.com/book/operating-systems-and-server-administration/unix/9781565920903/handling-a-process-and-a-user/the_expect_user_command
解决方案是使用命令行参数
这里 2 是传递的参数。 exp 文件中的参数处理如下
Solution is to use command line arguments
Here 2 is the argument being passed. The arguments are processed as follows in the exp file