题目1
用户建立脚本:users_create.sh
执行:users_create.sh userlist passlist
建立userlist列表中的用户
设定userlist列表中用户的密码为passlist列表中的密码
当脚本后面跟的文件个数不足两个的时候,报错
当文件行数不一致的时候报错
当文件不存在时候报错
当不是超级用户运行的时候报错
#!/bin/bash
ECHO()
{
echo -e "\033[$1m$2\033[0m"
}
if [ "$USER" != "root" ]
then
ECHO 31 "Error:Please run $0 with root!!"
elif [ "$#" -lt "2" ] ##运行时后面所跟字符不足两个
then
ECHO 31 "Error:Please input userlistfile and passwordlistfile following $0"
elif [ ! -e "$1" ] ##$1不存在
then
ECHO 31 "Error: $1 is not exist!!"
elif [ ! -e "$2" ] ##$2不存在
then
ECHO 31 "Error: $2 is not exist!!"
elif [ "`sed -n '$=' $1`" != "`sed -n '$=' $2`" ] ##$1文件的行数和$2文件的行数不相等
then
ECHO 31 "Error: $1's line is different then $2"
else
NUM&#