在bash脚本

时间:2017-05-23 09:30:42

标签: linux bash shell

任何人都可以解释这句话: -

value=$(seq -w -s '' $index $(($index + 100000)));

-w-s''的功能是什么?

这是使用它的代码部分:

for index in $(seq 1000); do
value=$(seq -w -s '' $index $(($index + 100000)))
eval array$index=$value
done

1 个答案:

答案 0 :(得分:0)

  • -w用于填充。因此1显示为01(最大值为2 位)。
  • -s是分隔符,因此-s ' '表示' '分开输出。使用-s ''将不使用任何分隔符,因此它将显示为 一长串。

bash-4.2$ seq -w -s ' ' 1 10
01 02 03 04 05 06 07 08 09 10

bash-4.2$ seq -w -s '' 1 10
01020304050607080910

为任何命令运行man--help页面以获取详细信息。

bash-4.2$ 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.

Mandatory arguments to long options are mandatory for short options too.
  -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