Seq in the shell magical

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.