我正在用 Python 编写一个应用程序,所以我正在为 Bash 编写一个安装文件。我遇到了一个问题,exit() 函数重复自身,而不是从 if 语句中调用 install 函数。这是代码...
#! /bin/bash
function install {
if [ $proceed == "y" ];
then
echo " "
echo "Thank you for installing the ACS Troubleshooter!"
echo " "
echo "The next line is going to ask for your password to initialize a download"
echo "sequence from the standard Ubuntu repositories"
echo " "
#sudo apt-get install testing
mkdir ~/Desktop/ACSapplicationFolder
sudo cp -r test ~/Desktop/ACSapplicationFolder
sudo chown -R ~/Desktop/ACSapplicationFolder
echo " "
echo " "
echo "The ACS Troubleshooter has been successfully installed."
read -p "Press [ENTER] key to open the ACS Troubleshooter > "
python gui.py &
elif [ $proceed == "n" ];
then
exit
fi
}
function bad_input {
echo "Please enter 'y' to continue the installation or 'n' to abort..."
read -p "> " proceed
if [ $proceed == "y" ];
then
install
elif [ $proceed == "n" ];
then
exit
else
bad_input
fi
}
function exit {
echo "The installation will exit."
echo " Please press [ENTER] to exit the installation or"
echo " press 'y' to reattempt installation."
read -p "> " yes
if [ "$yes" == "y" ];
then
clear
install
#else
#exit 1
fi
}
clear
echo " "
echo " *************************"
echo " "
echo " INSTALLATION: ACS TROUBLESHOOTER"
echo " "
echo " The installer is going to install Python, the language this application"
echo " is written in. Most computers don't have this installed by default so "
echo " we need to do this before running the Troubleshooter. It's going to ask "
echo " you to input your password one time to allow permission to install files "
echo " to sensitive directories."
echo " *************************"
echo " "
echo " "
echo "Should we continue with the installation? (type 'y' or 'n' then press enter) "
#echo "> "
read -p "> " proceed
if [ $proceed == "y" ];
then
install
elif [ $proceed == "n" ];
then
exit
else
bad_input
fi
唯一给我带来麻烦的函数是 exit() - 其他两个完全按预期工作......
测试脚本时,在初始提示符处给出“n”会运行 exit(),但在 exit() 提示符处给出“y”应该会重新运行 install(),但它会重新发出 exit() 提示符......感到沮丧......谁能回答为什么这样做?
*注意:我刚刚开始这样做,所以我知道 install() 和其他一些怪癖中存在错误,但我只是在填写扩展说明之前尝试测试这些功能......