脚本——for循环创建用户

#!/bin/bash
read -ep "请输入用户的数量:" sl
for i in `seq $sl`
do
  grep "user-$i" /etc/passwd > /dev/null
  if [ $? -ne 0 ]
  then
    useradd user-$i > /dev/null
    if [ $? -eq 0 ]
    then
      echo "user-$i" >> /root/user_name
      echo "user-$i"|passwd user-$i --stdin > /dev/null
      echo "user-$i 创建成功"
    fi
  else
    echo "user-$i 用户已经存在"
  fi
done

原文地址:https://www.cnblogs.com/hyydeali/p/12838554.html