Linux&shell之高级Shell脚本编程

您所在的位置:网站首页 linux编程菜单 Linux&shell之高级Shell脚本编程

Linux&shell之高级Shell脚本编程

2023-08-18 15:23| 来源: 网络整理| 查看: 265

创建菜单#!/bin/bash# testing the scriptclearechoecho -e "\t\t\tSys Admin Menu\n"echo -e "\t1.Display disk space"echo -e "\t2.Display logged on users"echo -e "\t3.Display memory usage"echo -e "\t0.Exit menu\n\n"echo -en "\t\tEnter option:"(这段代码很有意思,会显示目录的效果)创建菜单函数function diskspace {  clear  df -k}function whoseon {  clear  who}function memusage {  clear  cat /proc/meminfo}添加菜单逻辑case option in 0)   break ;; 1)   diskspace ;; 2)   whoseon ;; 3)   menusage ;; *)   clear   echo "Sorry,wrong selection" ;; esac  完整的菜单如下:  #!/bin/bash # testing the script function diskspace {   clear   df -k }  function whoseon {   clear   who }  function memusage {   clear   cat /proc/meminfo }  function menu {   clear   echo   echo -e "\t\t\tSys Admin Menu\n"   echo -e "\t1.Display disk space"   echo -e "\t2.Display logged on users"   echo -e "\t3.Display memory usage"   echo -e "\t0.Exit menu\n\n"   echo -en "\t\tEnter option:"   read -n 1 option } while [ 1 ] do menu caseoption in 0)   break ;; 1)   diskspace ;; 2)   whoseon ;; 3)   menusage ;; *)   clear   echo "Sorry,wrong selection" ;; esac  完整的菜单如下:  #!/bin/bash # testing the script function diskspace {   clear   df -k }  function whoseon {   clear   who }  function memusage {   clear   cat /proc/meminfo }  function menu {   clear   echo   echo -e "\t\t\tSys Admin Menu\n"   echo -e "\t1.Display disk space"   echo -e "\t2.Display logged on users"   echo -e "\t3.Display memory usage"   echo -e "\t0.Exit menu\n\n"   echo -en "\t\tEnter option:"   read -n 1 option } while [ 1 ] do menu caseoption in0)  break ;;1)  diskspace ;;2)  whoseon ;;3)  menusage ;;*)  clear  echo "Sorry,wrong selection" ;;esacecho -en "\n\n\t\tHit any key to continue"read -n 1 linedone

clear

本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/3259465.html,如需转载请自行联系原作者



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3