我正在爲bash中的程序編寫安裝腳本。安裝的第一部分檢測程序是否已安裝。這通過指定目錄中文件的存在來檢測。這部分工作正常。但是,如果舊版本存在,我希望用戶能夠升級到新版本。我認爲我的代碼是正確的,但它不起作用。/var/www/html/gvsms中有一個名爲.version的文件,它只是在文件中具有該程序的版本。我想將該數字與安裝程序的編號進行比較。不過,我不確定在if語句中如何。 If裏面可以有多個Ifs?這是我到目前爲止有:Bash驗證和條件語句
$installerver=1.1
$installedver=${cat /var/www/html/gvsms/.version}
echo "Installation beginning...."
echo " "
echo " "
echo -n "Checking to see if GVoice SMS Notification System was previously installed..."
if [ -a /var/www/html/gvsms/index.php ]; then
echo "Yes."
echo ""
echo "I have detected a previous installation of GVoice SMS Notification System."
if [ $installerver == $installedver ]; then
echo "The GVoice SMS Notification System is currently installed and is the same version as this installer. If you were trying to upgrade, please check the installer you downloaded and try again."
exit
fi
elif [ $installedver == "0.5" || $installedver == "1.0"]; then
while [[ "$yn" != "Yes" && "$yn" != "Y" && "$yn" != "y" && "$yn" != "yes" ]]; do
echo "Would you like to upgrade? Yes or no."
read -r upgrade
echo "$upgrade upgrade?"
echo "Is this correct? (Yes or No)"
read yn
done
echo "Upgrade proceeding..."
fi
echo "No."
echo "I have not detected a previous installation of GVoice SMS Notification System."
read -p "To proceed with installation at your own risk, press Enter. Otherwise Ctrl-C."
眼下與程序出現了錯誤:
./test.x: line 1: =1.1: command not found
./test.x: line 2: ${cat /var/www/html/gvsms/.version}: bad substitution
程序應該工作的方式是,如果檢測到文件,安裝的版本是不(或小於)與安裝程序相同,並且用戶說是升級,則應運行升級命令。如果用戶說不要升級,請退出腳本。
如果程序已安裝並且與安裝程序版本相同,則顯示錯誤消息並退出。
如果程序尚未安裝,請跳過重新確認安裝並繼續正常安裝。
這可能嗎? 謝謝!
我想你忘了把[ hashbang](http://en.wikipedia.org/wiki/Shebang_%28Unix%29)在你的腳本行。嘗試在第一行插入'!#/ bin/bash'。 – voithos 2011-05-23 22:21:15
我確實把它放在那裏,但它超出了這個粘貼的問題區域之外。 – Ross 2011-05-23 22:31:56