![](/img/trans.png)
[英]Bundle Expect with shell script to bypass installation of Expect
[英]expect with nested shell script
我有一个shell脚本batch_wrapper.sh,它接受用户输入,并调用另一个脚本batch.sh。 这两个脚本工作得很好。
现在,我创建了一个期望脚本test.sh,该脚本调用batch_wrapper.sh并提供输入参数。 但是,由于某种原因,未调用batch.sh脚本,我从期望脚本中生成了batch_wrapper.sh。 我怎样才能解决这个问题?
样本期望脚本为:
#!/usr/bin/expect
set timeout 2000
spawn "./batch_wrapper.sh"
expect "username" {send "Vikas\r" }
示例Shell脚本为:
batch_wrapper.sh
#!/bin/bash
echo "enter username"
read name
echo "your name is $name"
./batch.sh
批处理
#!/bin/bash
echo "Inside batch"
echo "exiting batch"
您的脚本随后将立即退出,因为没有任何事情要做。
您可以在期望脚本的最后一行中添加interact
或expect eof {}
作为最后一行,以使其处理剩余的输出:
$ cat lol.expect
#!/usr/bin/expect
set timeout 2000
spawn "./batch_wrapper.sh"
expect "username" {send "Vikas\r" }
expect eof {}
$ expect -f lol.expect
spawn ./batch_wrapper.sh
enter username
Vikas
your name is Vikas
Inside batch
exiting batch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.