1.wc统计行数
[root@localhost mnt]# wc -l username
3 username
[root@localhost mnt]# wc -l username | cut -d ” ” -f 1
3
2.echo $?
上一条命令执行成功显示 0 | 否则显示 1
[root@localhost mnt]# cat userna
cat: userna: No such file or directory
[root@localhost mnt]# echo $?
1
[root@localhost mnt]# cat username
linux1
linux2
linux3
[root@localhost mnt]# echo $?
0
[root@localhost mnt]#
#!/bin/bash
USERNUM=`wc -l /mnt/username | cut -d " " -f 1`
PASSWDNUM=`wc -l /mnt/password | cut -d " " -f 1`
cat /mnt/username >& /dev/null
if
[ $? = 0 ]
then
cat /mnt/password >& /dev/null
if
[ $? = 0 ]
then
if
[ ${USERNUM} = ${PASSWDNUM} ]
then
for N in $(seq 1 $USERNUM )
do
USERNAME=`sed -n ${N}p /mnt/username`
PASSWORD=`sed -n ${N}p /mnt/password`
id $USERNAME >& /dev/null
if
[ $? -ne 0 ]
then
useradd $USERNAME >& /dev/null
echo $PASSWORD | password --stdin $USERNAME >&/dev/null
echo "$USERNAME 创建成功"
else
echo "$USERNAME 已经存在"
fi
done
else
echo 用户名字与密码个数不匹配
fi
else
echo 密码文件不存在
fi
else
echo 用户文件不存在
fi
[root@localhost mnt]# cat password
123
456
789
[root@localhost mnt]# cat username
linux1
linux2
linux3
[root@localhost mnt]# sh jluser.sh
linux1 创建成功
linux2 创建成功
linux3 创建成功
[root@localhost mnt]# vim jluser.sh
[root@localhost mnt]# echo 123 > password
[root@localhost mnt]# cat password
123
[root@localhost mnt]# sh jluser.sh
用户名字与密码个数不匹配