我在Python中編寫應用程序,所以我正在編寫Bash的安裝文件。我有一個問題,exit()函數正在重複它自己,而不是從if語句中調用安裝函數。下面的代碼...Bash:功能重複,而不是運行指定的功能
#! /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
給我找麻煩的唯一功能是退出() - 其他兩個正在完全按照預期...
當測試腳本,賦予「N」的初始提示運行exit(),但在exit()提示符處輸入'y'應該重新運行install(),但它會重新發出exit()提示...變得沮喪......任何人都可以回答爲什麼這樣做?
*注:我剛開始這讓我知道在安裝的)錯誤(和其他一些怪癖,但我只是想在自己的擴展指令填充之前測試的功能...
你真的應該在發佈前剝離你的代碼,有很多東西與你的問題無關。 – user2719058
我已經改名退出()中止(),它有點工作。但是,當按Enter鍵退出時,我在終端中得到這個錯誤... ...「./ install.sh:line 52:[:==:unary operator expected」... 這是指在中止if語句的開始() – user2526871