shell编写简单的字符菜单管理脚本

1、创建shell文件

shell编写简单的字符菜单管理脚本

2、编写文件

#!/bin/bash
#func.sh
cat << eof
    ======================================
    = 1用户添加                          =
    = 2用户删除                          =
    = 3修改密码                          =
    = 4查看硬盘空间使用情况              =
    = 5查看内存空间使用情况              =
    = 6退出菜单                          =
    ======================================
eof
read -p "请输入你要完成的操作": num
case $num in
    1)
    read -p 'please input your name': name
    read -p 'please input your password': password
    echo "正在创建!!!"
    sleep 1
    useradd $name
    echo $password | passwd $name --stdin;
    echo "创建完成!!!"
    ;;
    2)
    read -p "请输入要删除的用户": name
    userdel $name
    echo "删除完成!!!"
    ;;
    3)
    read -p "请输入你要修改密码的用户名": name
    read -p "请输入要修改的密码": password
    echo $password | passwd $name --stdin > /dev/null 2>&1
    echo "修改完成!!!"
    ;;
    4)
    df -Th
    ;;
    5)
    free
    ;;
    6)
    echo "退出"
    ;;
esac

3、测试

    1)添加用户

shell编写简单的字符菜单管理脚本

shell编写简单的字符菜单管理脚本

    2)修改密码

shell编写简单的字符菜单管理脚本

    3)删除用户

shell编写简单的字符菜单管理脚本

    4)查看硬盘空间使用情况

shell编写简单的字符菜单管理脚本

    5)查看内存空间使用情况

shell编写简单的字符菜单管理脚本

    6)退出

shell编写简单的字符菜单管理脚本