因此,我有以下代碼(W.I.P),當我嘗試執行它時,終端立即打開並再次關閉。我不太確定是什麼原因造成的,所以如果有人能幫助我,我將不勝感激。代碼如下:終端打開,然後立即關閉
#!/bin/bash
#displays a menu with options for user to select
showMenu()
{
zenity --list \
--title="Menu - Choose an option" \
--column="Option No." --column="Option" \
--height="300" --width="475" \
1 "Install Gnome Disk Utility & gParted" \
2 "Create File - Demo.txt" \
3 "Remove File - Demo.txt" \
4 "Search for "BASH" in the .profile file (Case insensitive)" \
5 "Exit"
}
while [ 1 ]
do
CHOICE="$(showMenu)"
case $CHOICE in
"1")
#gets and installs gnome disk utility and gparted
sudo apt-get install gnome-disk-utility
sudo apt-get install gparted
;;
"2")
#creates a blank text file on the desktop called Demo.txt
touch /home/admin/Desktop/Demo.txt
zenity --info \
--text="File Demo.txt created on Desktop" \
;;
"3")
zenity --question \
--text="Are you sure you want to remove Demo.txt?" \
if ["$?" = 0]
then
#removes the Demo.txt file from the desktop
rm /home/admin/Desktop/Demo.txt
zenity --info \
--text="File has been removed" \
;;
"4")
#searches the .profile file for the word 'BASH' (Not case sensitive)
grep -i "BASH" /home/mintuser/.profile
;;
"5")
echo "Are you sure you want to exit? Press y/n"
read YN
case "$YN" in
"y")
exit
;;
"n")
#command for 'ESC' in BASH. Clears the screen
printf "\ec"
;;
*)
echo "Invalid option"
;;
esac
done
我的劇本工作的命令行版本,但它是當我去使用Zenity部件創建已發生問題的GUI。感謝您的閱讀和我可能收到的任何幫助。
雖然'[1]'碰巧你打算什麼它,它出於錯誤的原因(它總是真的有括號之間的1個參數 - '[0]'也將始終爲真)。您應該使用'while true'來代替。 – Kevin 2013-02-20 22:12:28
這樣可以解決問題嗎? – user2084095 2013-02-20 22:22:59
可能不是,但你應該牢記它。 – Kevin 2013-02-20 22:24:35