seq下令
seq命令
seq命令:
用来产生连续的数字。最常见的用法是用在for循环中。
用法:
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 (default: %g) -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 If FIRST or INCREMENT is omitted, it defaults to 1. That is, an omitted INCREMENT defaults to 1 even when LAST is smaller than FIRST. FIRST, INCREMENT, and LAST are interpreted as floating point values. INCREMENT is usually positive if FIRST is smaller than LAST, and INCREMENT is usually negative if FIRST is greater than LAST. When given, the FORMAT argument must contain exactly one of the printf-style, floating point output formats %e, %f, %g
举例:
$for i in `seq 0 10`;do echo "$i";done 0 1 2 3 4 5 6 7 8 9 10
加上 -w 参数之后:
$for i in `seq -w 0 10`;do echo "$i";done 00 01 02 03 04 05 06 07 08 09 10 数字的宽度一样了,使用0来填充,上面的Description其实也已经讲的很清楚了。
当然还可以指定连续数字之间的间隔:
$for i in `seq -w 0 2 10`;do echo "$i";done 00 02 04 06 08 10
当然也可以逆序来使用,比如说:
$for i in `seq -w 5 -1 1`;do echo "$i";done 5 4 3 2 1
-s 参数用来改变两个数字之间的间隔符,默认是回车:“\n”:
试着改一下:
$for i in `seq -s "----" -w 0 23`;do echo "$i";done 00----01----02----03----04----05----06----07----08----09----10----11----12----13----14----15----16----17----18----19----20----21----22----23
至于 -f 参数:
$seq -f "nigel.%g" 1 5 nigel.1 nigel.2 nigel.3 nigel.4 nigel.5 $seq -f "nigel.%e" 1 5 nigel.1.000000e+00 nigel.2.000000e+00 nigel.3.000000e+00 nigel.4.000000e+00 nigel.5.000000e+00 $seq -f "nigel.%f" 1 5 nigel.1.000000 nigel.2.000000 nigel.3.000000 nigel.4.000000 nigel.5.000000 大家应该可以看出区别了
小命令,很实用。
===============================全文完===================================