我在BusyBox linux安装上运行了一个bash脚本。
当我运行我的脚本时,在提示符处我必须输入yes
并输出以下内容:
Remove existing upgrades stored on this device?
Please answer yes or no.
Remove existing upgrades stored on this device? Please answer yes or no.
Remove existing upgrades stored on this device?
在yes
的第二个条目上,它会进入并运行case
循环中的yes下的命令。有什么想法我必须输入两次吗?
以下是我正在使用的代码示例:
while true; do
read -p " Remove existing upgrades stored on this device? " yn
case $yn in
[Yy]* )
echo " Moving into folder."
echo " Removing existing upgrade files."
echo " Moving back to original folder."
echo " Complete.";
break;;
[Nn]* )
echo " Enough space is available."
echo " This script can be run again if required.";
break;;
* )
echo "Please answer yes or no."
echo "";;
esac
done
答案 0 :(得分:0)
我已经重新开发了脚本,这次使用IF Statement
和我的解决方案。
如果有人建议如何保持while
循环,我仍然希望听到它。
read -p " Remove existing upgrades stored on this device? (y/n) " RESP
if [ "$RESP" = "y" ]; then
echo " Moving into folder."
echo " Removing existing upgrade files."
echo " Moving back to original folder."
echo " Complete.";
else
echo " Enough space is available."
echo " This script can be run again if required.";
fi