linux-tutorial/codes/shell/示例脚本/菜单/使用select命令.sh

38 lines
581 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
2019-10-10 08:56:31 +08:00
2019-05-10 11:17:57 +08:00
# using select in the menu
function diskspace {
2019-10-10 08:56:31 +08:00
clear
df -k
2019-05-10 11:17:57 +08:00
}
function whoseon {
2019-10-10 08:56:31 +08:00
clear
who
2019-05-10 11:17:57 +08:00
}
function menusage {
2019-10-10 08:56:31 +08:00
clear
cat /proc/meminfo
2019-05-10 11:17:57 +08:00
}
PS3="Enter option:"
select option in "Display disk space" "Display logged on users" "Display memory usage" "Exit program"
do
2019-10-10 08:56:31 +08:00
case $option in
"Exit program")
break ;;
"Display disk space")
diskspace ;;
"Display logged on users")
whoseon ;;
"Display memory usage")
menusage ;;
*)
clear
echo "Sorry, wrong selection" ;;
esac
2019-05-10 11:17:57 +08:00
done
clear