【发布时间】:2017-02-25 00:05:16
【问题描述】:
我的 RPi 上的这个 while true 循环有问题。我希望它在启动后始终等待用户输入。以下脚本在我手动运行时完美运行:
#!/bin/bash
while true; do
read input
if [ "$input" = "1" ]; then
echo "message1"
elif [ "$input" = "2" ]; then
echo "message2"
elif [ "$input" = "3" ]; then
echo "message3"
else
echo "error"
fi
done
但是当我在启动时通过将脚本添加到 rc.local 来运行脚本时,它不会等待输入。相反,它只是无限地呼应“错误”。我不明白。为什么手动运行时可以,开机时卡住?
谢谢!
【问题讨论】:
-
启动脚本运行时,它们的输入没有连接到控制台。
标签: bash while-loop