如果在调用shell脚本后使用,则Expect无效

时间:2016-07-05 11:04:26

标签: bash shell expect

我有shell脚本测试有以下内容:

read -s -n 1 -p "press enter to continue..." key
if [[ $key = "" ]]; then
    echo 'You pressed enter!'
else
    echo "You pressed '$key'"
fi

我用以下脚本调用上面的脚本。但是当我执行下面的脚本然后它挂起在输入级别

#!/bin/bash
/usr/bin/expect <<EOF
spawn ./test.sh
expect "Press enter to continue..."
send "\r"
EOF

1 个答案:

答案 0 :(得分:1)

解答: 您忘记了if语句中的then

顺便说一句:
您可以像这样使用REPLY变量:

#!/bin/bash
read -r -n 1 -p "press enter to continue..."
if [[ $REPLY = "" ]] ; then
    echo 'You pressed enter!'
else
    echo "You pressed '$REPLY'"
fi