双重输入运行脚本

时间:2014-10-31 08:53:22

标签: bash busybox

我在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

1 个答案:

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