有人可以帮我添加一个简单的 while 循环吗?如果它与脚本相关就更好了

有人可以帮我添加一个简单的 while 循环吗?如果它与脚本相关就更好了

这是我的脚本,尝试添加一个,但一直出错。非常感谢大家的帮助。

#!/bin/sh
#Name:gamer
#Date Created: 12/6/2015
#last modified: 12/8/2015
#Desc/Purpose: Updating and installing apps.
DATE=$(date -d "$1" +"%m_%d_%Y");
condition=y
while [ $condition = "y" ] || [ $condition = "Y" ]
do

clear

echo -n "Do you know how to Update OS y/n:"
read answer

if [ $answer = "y" ] || [ $answer = "Y" ]; then
    echo "Good update the os then." 

elif [ $answer = "n" ]; then
    echo "would you like me to update it for you:" 
    read response
    if  [ $response = "y" ]; then
        echo "updating os!"
            sudo apt-get update os
    fi
fi
clear
echo -n "would you like to install apps:" 
read answer

if [ $answer = "y" ] || [ $answer = "Y" ]; then
        echo "A) Install Webmin"
        echo "B) Install Apache"
        echo "C) Install gnome shell"
        echo "D) get ubuntu desktop"
        echo "E) Add new user"
        echo "F) get Xubuntu Desktop"
        echo "G) Install openbox"
        echo "H) remove Libre office"
        echo "I) I don't want to install anything"
        read option
fi
        case $option in 
            A) sudo apt-get install webmin ;;
            B) sudo apt-get install apache ;;
            C) sudo apt-get install gnome-shell ;;
            D) sudo apt-get install ubuntu-desktop ;;
            E) sudo useradd ;;
            F) sudo apt-get install xubuntu-desktop ;;
            G) sudo apt-get install openbox ;;
            H) sudo apt-get remove --purge libreoffice* ;;
            I) echo "You can always do it later" ;;
            *) echo "Please select one of the options" ;;
        esac


done

答案1

遗憾的是,您没有解释要修复的具体错误是什么,但无论如何,这个命令:

sudo apt-get update os

会报错:

E: The update command takes no arguments

修复很简单,如下:

sudo apt-get update

“有点”,因为它没有按照声明echo所说的那样:

echo "updating os!"
sudo apt-get update

这只会更新软件包索引,不会更新操作系统中的任何内容。也许您正在寻找:

sudo apt-get upgrade

不确定这是否是个问题,但您的while循环永远不会退出,因为变量在开始时condition设置为,并且以后永远不会改变。也许您想在某个时候将其设置为,或者添加一个语句。将“条件”重命名为实际有意义的名称也是不错的选择。或者要明确地使其成为无限循环,请将其更改为。ynbreakwhile true

相关内容