#!/bin/bash
function mod_g()
{
sudo usermod -G $2 $1
}
function mod_p()
{
sudo passwd $1
}
function add_user()
{
echo "请输入用户名";
read user_name;
sudo useradd $user_name
sudo passwd $user_name
echo "设置用户所在组"
read grp;
mod_g $user_name $grp
}
function del_user()
{
echo "请输入要删除的用户名称"
read user_name
sudo userdel $user_name
}
function mod_user()
{
echo "请输入要修改的用户名称"
read user_name
echo "0. 修改密码"
echo "1. 修改组名"
read opt
if [ $opt="0" ];then
mod_p $user_name
elif [ $opt="1" ];then
echo "设置组名称"
read grp
mod_g $user_name $grp
fi
}
function query_user()
{
more /etc/passwd
}
echo "please chose the options"
echo "0.add user"
echo "1.del user"
echo "2.mod user"
echo "3.query user"
read choice
if [ $choice = "0" ];then
{
add_user
}
elif [ $choice = "1" ];then
{
del_user
}
elif [ $choice = "2" ];then
{
echo "请输入要修改的用户名称"
read user_name
mod_user $user_name
}
elif [ $choice = "3" ];then
{
query_user
}
fi
shell脚本主要有两点需要注意的是其一 #!/bin/sh 或者#!/bin/bash的区别,不同版本是不同的
其二shell是解释型语言,解释一句,执行一句