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
  • 相关阅读:
    Dockerfile-ADD命令-转载
    华为云上上传镜像到在线镜像仓库
    什么是4D(DRG、DLG、DOM、DEM)数据
    视频对接资料
    OpenLayer改变切片地图的样式-滤镜效果
    Docker-挂载宿主机目录到容器
    RTSP在线视频环境搭建2-海康摄像头
    配置自己风格的Clang-Format-Xcode
    GCDAsyncUdpSocket的使用
    react-native component function
  • 原文地址:https://www.cnblogs.com/wsy0202/p/11062146.html
Copyright © 2011-2022 走看看