2017-06-14 102 views
-1

shell脚本期望和产卵命令

a.sh的其实我写2个脚本

#!/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: 

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

回答

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