新建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

Ubuntu下使用dialog制作菜单执行简单脚本

上下光标选择菜单,选择3,显示

Ubuntu下使用dialog制作菜单执行简单脚本

选择0,退出

脚本用mktemp新建临时文件保存dialog数据

 

相关文章:

  • 2022-03-02
  • 2021-09-09
  • 2022-12-23
  • 2021-06-23
  • 2021-05-18
  • 2022-12-23
  • 2021-04-29
  • 2021-10-07
猜你喜欢
  • 2022-12-23
  • 2021-11-14
  • 2022-02-25
  • 2022-12-23
  • 2021-05-22
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案