shell-while循环
程序员文章站
2024-03-23 21:02:10
...
[[email protected] user]# cat while.sh
#!/bin/bash
i=1
while [ $i -le 20 ]
do
useradd stu$i
echo "123456" | passwd --stdin stu$i >>users.txt
echo "stu$i"
let i++
done
[[email protected] user]# sh while.sh
useradd:用户“stu1”已存在
stu1
stu2
stu3
stu4
stu5
stu6
stu7
stu8
stu9
stu10
stu11
stu12
stu13
stu14
stu15
stu16
stu17
stu18
stu19
stu20
[[email protected] user]# tail -20 /etc/passwd
stu1:x:1009:1009::/home/stu1:/bin/bash
stu2:x:1010:1010::/home/stu2:/bin/bash
stu3:x:1011:1011::/home/stu3:/bin/bash
stu4:x:1012:1012::/home/stu4:/bin/bash
stu5:x:1013:1013::/home/stu5:/bin/bash
stu6:x:1014:1014::/home/stu6:/bin/bash
stu7:x:1015:1015::/home/stu7:/bin/bash
stu8:x:1016:1016::/home/stu8:/bin/bash
stu9:x:1017:1017::/home/stu9:/bin/bash
stu10:x:1018:1018::/home/stu10:/bin/bash
stu11:x:1019:1019::/home/stu11:/bin/bash
stu12:x:1020:1020::/home/stu12:/bin/bash
stu13:x:1021:1021::/home/stu13:/bin/bash
stu14:x:1022:1022::/home/stu14:/bin/bash
stu15:x:1023:1023::/home/stu15:/bin/bash
stu16:x:1024:1024::/home/stu16:/bin/bash
stu17:x:1025:1025::/home/stu17:/bin/bash
stu18:x:1026:1026::/home/stu18:/bin/bash
stu19:x:1027:1027::/home/stu19:/bin/bash
stu20:x:1028:1028::/home/stu20:/bin/bash