加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell 字符菜单管理

发布时间:2020-12-15 21:13:22 所属栏目:安全 来源:网络整理
导读: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 )

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读