首页 > 系统服务 > 详细

shell 字符菜单管理

时间:2019-06-20 23:59:00      阅读:201      评论:0      收藏:0      [点我收藏+]

1、创建一个脚本func.sh

脚本如下func2.sh

技术分享图片
#!/bin/bash

function menu(){
title="My Menu"
url="www.lampym.com"
time=`date +%Y-%m-%d`
cat << eof

########################################
        $title
########################################
*    1)add a user
*    2)set password for user
*    3)delete e user
*    4)print disk sapce
*    5)print mem space
*    6)quit
########################################
$url              $time
########################################
eof
}
func2.sh

2、创建脚本index.sh

技术分享图片
#!/bin/bash

. func2.sh

clear
menu

while true
do    
     read -p "please input a option:" option
     case $option in
        1) 
          read -p "add a user:" name
          useradd $name  > /dev/null
          if [ $? -eq 0 ] ;then
            str="user ${name} is created successfully"
            echo -e "\033[30;47m$str\033[0m"
          else
            str="user ${name} is created failly!"
            echo -e "\033[31;47m$str\033[0m"
          fi;;
        2) 
         read -p "input the user:" user
         read -p "set password for the user:" passwd
         echo $passwd | passwd --stdin $user > /dev/null
         if [ $? -eq 0 ] ;then
            str="${user}‘s password set successfully!"
            echo -e "\033[30;47m$str\033[0m"
         else
            str="${user}‘s password set failly"
            echo -e "\033[31;47m$str\033[0m"
            
         fi;;
        3) 
             read -p "input a user:" user
         userdel -r $user
         if  [ $? -eq 0 ] ;then
            str="$user delete successfully!"
            echo -e "\033[30;47m$str\033[0m"
         else
            str="$user delete failly"
            echo -e "\033[31;47m$str\033[0m"
         fi
            ;;
        4) echo "你选择了第四个选项";;
        5) echo "你选择了第五个选项";;
        6) echo "你选择了退出!"
          break    ;;
        7) clear
           menu
      esac
done
index.sh

 

shell 字符菜单管理

原文:https://www.cnblogs.com/wsy0202/p/11062146.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!