新建test5
#!/bin/bash #using select in the menu temp=$(mktemp -t test.XXXXXX) temp2=$(mktemp -t test2.XXXXXX) function diskspace { df -k > $temp dialog --textbox $temp 20 60 } function whoseon { who > $temp dialog --textbox $temp 20 60 } function menusage { cat /proc/meminfo > $temp dialog --textbox $temp 20 60 } while [ 1 ] do dialog --menu "Sys Admin Menu" 20 30 10 1 "Display disk space" 2 "Display logged on users" 3 "Display memory usage" 0 "Exit" 2>$temp2 if [ $? eq 1 ] then break fi selection=$(cat $temp2) case $selection in 0) break;; 1) diskspace;; 2) whoseon;; 3) menusage ;; *) dialog --msgbox "Sorry,invalid selection" 10 30 esac done rm -rf $temp 2> /dev/null rm -rf $temp2 2> /dev/null
修改文件权限
chmod 777 test5
执行
./test5
上下光标选择菜单,选择3,显示
选择0,退出
脚本用mktemp新建临时文件保存dialog数据