我有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
答案 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