#!/bin/bash
read -p "Please input username: " name
id $name &> /dev/null
if [ $? -ne 0 ];then
useradd $name && echo "$name create success."
read -sp "Please input password: " pw
echo
if [ ${#pw} -ge 7 ];then
read -sp "Please again input password: " pw2
echo
if [ $pw = $pw2 ];then
echo $pw |passwd --stdin $name &> /dev/null
echo "Password create success."
else
echo "Inconsistency of password input."
fi
else
echo "Password input error."
fi
else
echo "$name already exist."
fi
思路:
转载于:https://blog.51cto.com/13765357/2121426