![有人可以帮我添加一个简单的 while 循环吗?如果它与脚本相关就更好了](https://linux22.com/image/986225/%E6%9C%89%E4%BA%BA%E5%8F%AF%E4%BB%A5%E5%B8%AE%E6%88%91%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84%20while%20%E5%BE%AA%E7%8E%AF%E5%90%97%EF%BC%9F%E5%A6%82%E6%9E%9C%E5%AE%83%E4%B8%8E%E8%84%9A%E6%9C%AC%E7%9B%B8%E5%85%B3%E5%B0%B1%E6%9B%B4%E5%A5%BD%E4%BA%86.png)
这是我的脚本,尝试添加一个,但一直出错。非常感谢大家的帮助。
#!/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
设置为,并且以后永远不会改变。也许您想在某个时候将其设置为,或者添加一个语句。将“条件”重命名为实际有意义的名称也是不错的选择。或者要明确地使其成为无限循环,请将其更改为。y
n
break
while true