2017-06-14 106 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