shell菜单选择

我们会遇到很多进入后台系统的时候,会根据选择,进入不同的系统,下面是一个简单的例子:

#!/bin/sh

function menu ()
{
 cat << EOF
----------------------------------------
|************Menu Home Page ************|
----------------------------------------
`echo -e "\033[35m 1)Person\033[0m"`
`echo -e "\033[35m 2)Admin\033[0m"`
`echo -e "\033[35m 3)Menu\033[0m"`
`echo -e "\033[35m 4)Quit\033[0m"`
EOF
read -p "input you num:" num1
case $num1 in
 1)
  echo "Welcome to people!!"
  person_menu
  ;;
 2)
  echo "Welcome to admin!!"
  admin_menu
  ;;
 3)
  clear
  menu
  ;;
 4)
  exit 0
  ;;
 *)
  echo "Input Error ,Please again !!!"
  exit 1
  ;;
esac
}
 
function person_menu ()
{
 cat << EOF
----------------------------------------
|***************PERSON****************|
----------------------------------------
`echo -e "\033[35m 1)Zhangsan\033[0m"`
`echo -e "\033[35m 2)Lisi\033[0m"`
`echo -e "\033[35m 3)Wangwu\033[0m"`
`echo -e "\033[35m 4)Back\033[0m"`
EOF
read -p "input you num:" num2
case $num2 in
 1)
  echo "Welcome to Zhangsan !!"
  person_menu
  ;;
 2)
  echo "Welcome to Lisi !!"
  person_menu
  ;;
 3)
  echo "Welcome to Wangwu !!"
  person_menu
  ;;
 4)
  clear
  menu
  ;;
 *)
  echo "the is Fail!!"
  person_menu
esac
}
 
function admin_menu ()
{
 cat << EOF
----------------------------------------
|***************ADMIN****************|
----------------------------------------
`echo -e "\033[35m 1)Admin\033[0m"`
`echo -e "\033[35m 2)Admin1\033[0m"`
`echo -e "\033[35m 3)Admin2\033[0m"`
`echo -e "\033[35m 4)Back\033[0m"`
EOF
read -p "input you num:" num3
case $num3 in
 1)
  echo "Welcome to Admin !!"
  admin_menu
  ;;
 2)
  echo "Welcome to Admin1 !!"
  admin_menu
  ;;
 3)
  echo "Welcome to Admin2 !!"
  admin_menu
  ;;
 4)
  clear
  menu
  ;;
 *)
  echo "the is Fail!!"
  admin_menu
esac
}
menu
运行结果:

根据选择进入不同的选项

 

posted @ 2019-08-14 16:44  醉城、  阅读(2984)  评论(0编辑  收藏  举报