zoukankan      html  css  js  c++  java
  • shell 字符菜单管理

    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 "33[30;47m$str33[0m"
              else
                str="user ${name} is created failly!"
                echo -e "33[31;47m$str33[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 "33[30;47m$str33[0m"
             else
                str="${user}'s password set failly"
                echo -e "33[31;47m$str33[0m"
                
             fi;;
            3) 
                 read -p "input a user:" user
             userdel -r $user
             if  [ $? -eq 0 ] ;then
                str="$user delete successfully!"
                echo -e "33[30;47m$str33[0m"
             else
                str="$user delete failly"
                echo -e "33[31;47m$str33[0m"
             fi
                ;;
            4) echo "你选择了第四个选项";;
            5) echo "你选择了第五个选项";;
            6) echo "你选择了退出!"
              break    ;;
            7) clear
               menu
          esac
    done
    index.sh
  • 相关阅读:
    MySQL
    权限(二)
    权限(一)
    化栈为队
    栈的最小值
    实现简易版react中createElement和render方法
    12.整数转罗马数字
    call,apply,bind的理解
    8. 字符串转换整数 (atoi)
    172.阶乘后的0
  • 原文地址:https://www.cnblogs.com/wsy0202/p/11062146.html
Copyright © 2011-2022 走看看