shell 脚本期望和生成命令

shell script expect and spawn commands

实际上我正在写

的 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:

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

a.sh写完say hii两次

#!/bin/sh

PASSPHRASE="PASS"
for i in 1 2
do
    echo "say hii:"
    IFS= read -r line && echo "[=10=] 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