标签:bash
添加10个用户user1到user10,密码同用户名;但要求只有用户不存在的情况下才能添加;
接受一个参数:
add: 添加用户user1..user10
del: 删除用户user1..user10
其它:退出
代码 #!/bin/bash # A=$1 if [ $A == add ];then for I in {1..10};do USER=user$I if ! id $USER &> /dev/null ;then useradd user$I &> /dev/null echo "user$I" | passwd user$I --stdin &>/dev/null echo "Add user$I OK" else echo "user$I ex" fi done elif [ $A == del ];then for I in {1..10};do USER=user$I if id $USER &>/dev/null ;then userdel user$I \rm -r /home/user$I echo "delete user$I OK" else echo "user$I is not ex" fi done else echo "Usage: ./foruseradd.sh "add" "de"" fi
标签:bash
原文地址:http://sharewaytogo.blog.51cto.com/2816479/1846624