shell's seq (generates an integer between two numbers), expr generates a random number

1, Generate integers between consecutive numbers (including positive integers and negative integers) ...

1, Generate integers between consecutive numbers (including positive integers and negative integers)

[root@server51 ~]# seq --help Usage: seq [OPTION]... LAST or: seq [OPTION]... FIRST LAST or: seq [OPTION]... FIRST INCREMENT LAST Print numbers from FIRST to LAST, in steps of INCREMENT. -f, --format=FORMAT use printf style floating-point FORMAT -s, --separator=STRING use STRING to separate numbers (default: \n) -w, --equal-width equalize width by padding with leading zeroes --help display this help and exit --version output version information and exit

The above results show that there are - F, - s, - W options.
Without options, you can generate integers between two numbers, positive integers and negative integers:

[root@server51 ~]# seq 1 5 1 2 3 4 5 [root@server51 ~]# seq -5 -1 -5 -4 -3 -2 -1

-f option (format), format output:

[root@server51 ~]# seq -f "%3g" 1 5 1 2 3 4 5 [root@server51 ~]# seq -f "%03g" 1 5 001 002 003 004 005

-w option (width), specify the width output:

[root@server51 ~]# seq -w 1 05 01 02 03 04 05 [root@server51 ~]# seq -w 1 005 001 002 003 004 005 [root@server51 ~]# seq -w 001 5 001 002 003 004 005 [root@server51 ~]# seq -w 0001 5 0001 0002 0003 0004 0005

-s option (separator), specifying that the separator is line feed by default:

[root@server51 ~]# seq 1 5 1 2 3 4 5 [root@server51 ~]# seq -s "" 1 5 12345 [root@server51 ~]# seq -s " " 1 5 1 2 3 4 5 [root@server51 ~]# seq -s "`echo -e "\t"`" 1 5 1 2 3 4 5

2, Generate random number
Generate random numbers within 1-10

[root@server51 ~]# expr $[RANDOM%10+1] 8 [root@server51 ~]# expr $[RANDOM%10+1] 5 [root@server51 ~]# expr $[RANDOM%10+1] 5 [root@server51 ~]# expr $[RANDOM%10+1] 8 [root@server51 ~]# expr $[RANDOM%10+1] 7 [root@server51 ~]# expr $[RANDOM%10+1] 5 [root@server51 ~]# expr $[RANDOM%10+1] 3

expr $[RANDOM%10] will generate a random number between 1 and 9

4 May 2020, 17:49 | Views: 6793

Add new comment

For adding a comment, please log in
or create account

0 comments