『练习』:编写create_user.sh脚本<1>please input username:lee ,当lee存在,输出显示"lee is exist";<2>please input username:lee1 ,当lee1不存在,please input password: 输入密码,建立lee1并设定密码;<3>please input username: exit ,当输入为exit时退出循环
<使用函数方式+test命令实现>
exit 0
命令执行正确—>退出
#!/bin/bash
CREATE()
{
read -p "Please Input Username:" USERNAME
[ "$USERNAME" = "exit" ] && {
echo Bye~
exit 0
}
useradd $USERNAME &> /dev/null && {
read -p "Please Input Password:" -s PASSWORD
echo ""
echo $PASSWORD | passwd --stdin $USERNAME &> /dev/null
echo -e "\033[32m$USERNAME is created successfully !!!\033[0m"
} || {
echo -e "\033[31m$USERNAME is already exist !!!\033[0m"
}
CREATE
}
CREATE