gpt4 book ai didi

linux - 在bash脚本中计算并赋值

转载 作者:太空宇宙 更新时间:2023-11-04 05:49:54 24 4
gpt4 key购买 nike

谁能解释一下这个说法:-

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

最佳答案

  • -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

关于linux - 在bash脚本中计算并赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44130945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com