shell脚本期望和生成命令

时间:2017-06-14 11:57:10

标签: bash shell expect

其实我正在编写2个

的脚本

a.sh

#!/bin/sh

PASSPHRASE="PASS"
for i in 1 2
do
echo "say hii:"
done

另一个剧本 b.sh

#!/usr/bin/expect -f

spawn ./a.sh
sleep 2
for {set x 1} {$x<3} {incr x} {
expect "say hii:"
send "hii\r"
sleep 10
interact
}

executing ./b.sh

所以这是第一次发送say hii: "and we are sending hii"

for the second time it getting struck in say hii:

所以我想发送两次意味着有多少时间用于循环。

1 个答案:

答案 0 :(得分:0)

a.sh写完后说完hii两次

#!/bin/sh

PASSPHRASE="PASS"
for i in 1 2
do
    echo "say hii:"
    IFS= read -r line && echo "$0 read: $line"
done

b.sh

#!/usr/bin/expect -f

spawn ./a.sh
sleep 2
for {set x 1} {$x<3} {incr x} {
    expect "say hii:"
    send "hii\r"
    sleep 1
}
interact