1.命令行菜单
#!/bin/bash
#simple script menu
function diskspace {
clear
df -k
}
function whoseon {
clear
who
}
function memusage {
clear
free -m
}
function menu {
clear
echo
echo -e "\t\t\t SysAdmin Menu \n"
echo -e "\t 1.Dispaly Disk usage"
echo -e "\t 2.Dispaly who are on"
echo -e "\t 3.Display memuage "
echo -en "\t\tEnter your choice:"
read -n 1 option
}
while [ 1 ]
do
menu
case $option in
0)
break ;;
1)
diskspace ;;
2)
whoseon ;;
*)
clear
echo "sorry wrong selection" ;;
esac
echo -en "\n\n\t\tHit any key to continue"
read -n 1 option
done
clear
//result
SysAdmin Menu
1.Dispaly Disk usage
2.Dispaly who are on
3.Display memuage
Enter your choice:^C
2.select 语法
#!/bin/bash
#simple script menu
function diskspace {
clear
df -k
}
function whoseon {
clear
who
}
function memusage {
clear
free -m
}
PS3="Enter your OPtion:"
select option in "disk" "who" "memory" "exit"
do
case $option in
"disk")
diskspace ;;
"who")
whoseon ;;
"memory")
meusage ;;
"exit")
break ;;
*)
clear
echo "Sorry wrong selection" ;;
esac
done
clear
//result
Enter your OPtion:
1) disk
2) who
3) memory
4) exit
Enter your OPtion:
3.图形化的
#!/bin/bash
#using dialog to create menu
temp=`mktemp -t test.XXXXXX`
temp2=`mktemp -t test.XXXXXX`
function diskspace {
df -k > $temp
dialog --textbox $temp 20 50
}
function whoseon {
who > $temp
dialog --textbox $temp 20 50
}
function memusage {
free -m > $temp
dialog --textbox $temp 20 50
}
while [ 1 ]
do
dialog --menu "Sys Menu" 20 30 10 1 "disk" 2 "users" 3 "memory" 0 "exit" 2> $temp2
if [ $? -eq 1 ]
then
break
fi
selection=`cat $temp2`
case $selection in
1)
diskspace ;;
2)
whoseon ;;
3)
memusage ;;
0)
break ;;
*)
dialog --msgbox "Sorry invalid selection" 10 30
esac
done
rm -f $temp 2> /dev/null
rm -r $temp2 2> /dev/null