for添加用户

#!/bin/bash

#接受一个参数:
#add: 添加用户user1..user10
#del: 删除用户user1..user10
#其它:退出 #定义变量
ADD=add
DEL=del #判断参数输入是否正确
if [ $# -ne 1 ]; then
echo "Usage:./shell.sh add|del."
exit 1 #输入add,添加用户
elif [ $1 = $ADD ]; then
for I in {1..10}; do
if ! id "user$I" &> /dev/null; then
useradd -M "user$I"
echo "add user$I OK."
else
echo "user$I exist.There's no need to newadd."
fi
done
#输入del,删除用户
elif [ $1 = $DEL ]; then
for I in {1..10}; do
if id "user$I" &> /dev/null; then
userdel -r "user$I"
echo "del user sucessfully."
else
echo "user$I not exist,no need to delete."
fi
done
else
echo "tip:./shell.sh add|del."
fi
上一篇:[Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)


下一篇:Spring+SpringMVC+MyBatis+easyUI整合优化篇(十四)谈谈写博客的原因和项目优化