我正在嘗試使用expect
與bash
腳本交談,但我錯過了一些東西。我的腳本是:expect vs. bash read
#!/bin/bash
echo -n "foo? "
read
echo $REPLY
和我expect
腳本是:
#!/usr/bin/expect
spawn ./script.sh
expect "foo? "
send "bar\r\n"
但我從來沒有看到bar
當我運行該腳本expect
。我在這裏錯過了什麼?
我正在嘗試使用expect
與bash
腳本交談,但我錯過了一些東西。我的腳本是:expect vs. bash read
#!/bin/bash
echo -n "foo? "
read
echo $REPLY
和我expect
腳本是:
#!/usr/bin/expect
spawn ./script.sh
expect "foo? "
send "bar\r\n"
但我從來沒有看到bar
當我運行該腳本expect
。我在這裏錯過了什麼?
阿呆,我需要添加interact
我expect
腳本,以便它可以完成「互動」的劇本:
#!/usr/bin/expect
spawn ./script.sh
expect "foo? "
send "bar\r\n"
interact
我找到了答案問這個問題here兩分鐘後。
我不熟悉以及與expect
語法,但是你值得嘗試autoexpect
:
autoexpect ./script.sh
它將運行script.sh
之後你會完成運行它的預期腳本script.exp
將在當前目錄中創建。
之後,你可以編輯它,如果你需要調整它的東西。
您不需要發送'\ n',只需要'\ r' - 您正在模擬「點擊回車」。 –