所以我有以下代码(WIP),当我尝试执行它时,终端会立即打开并再次关闭。我不太确定是什么原因造成的,所以如果有人能帮助我,我将不胜感激。代码如下:
#!/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 时,问题就发生了。感谢您的阅读和我可能收到的任何帮助。