Add 20 users to the CLASS01 group in bulk, the user name begins with STD, ends with a number, format: STD01---STD20
Method 1
#!/bin/shgroupadd class01a=stdfor ((i=1;i<=20;i++)) doif [$i-lt];thenusername= "$a" 0 "$i" elseusername= $a $ Ifiuseradd-g class01-m $usernamedone
Method 2:
#!/bin/bashgroupadd class01for i in {1..20}doif [$i-lt];thenuseradd "std0$i"-G Class01elseuseradd "Std$i"-G class 01fidone
Method 3: This method is the simplest and most efficient, the use of SEQ, there will be unexpected effect
For i in ' seq-w ';d o useradd-g class01 sdt$i;done
Parameters for seq:
-F,--format=format use printf style floating-point format (default:%G)
-S,--separator=string use STRING to separate numbers (default:/N)
-W,--equal-width equalize width by padding with leading zeroes
The-F option specifies the format
Seq-f "%3g" 1 10
% the number of digits specified after the default is "%g",
"%3G" then the number of digits is not enough space
# seq-f "%03g" 1 11
001
002
003
004
005
006
007
008
009
010
011
% preceded by the specified string, sed-f "%03g" 1 11 so the number of digits is less than 0
# seq-f "test%03g" 8 12
test008
test009
test010
test011
test012
-W Specifies that the output number is equal to the width cannot be used with-f
# seq-w 1 10
The output is the same width
This article is from the "Boyhack" blog, make sure to keep this source http://461205160.blog.51cto.com/274918/1920294
Seq in the shell magical