shell script中怎麼在數字前補上位數的零呢?
for i in $(seq -f "%05g" 10 15)
do
echo $i
done
will produce the following output:
00010
00011
00012
00013
00014
00015
aa
More generally,
bash
has printf
as a built-in so you can pad output with zeroes as follows:$ i=99
$ printf "%05d\n" $i
00099
You can use the
-v
flag to store the output in another variable:$ i=99
$ printf -v j "%05d" $i
$ echo $j
00099
numbers - Zero Padding In Bash - Stack Overflow
http://stackoverflow.com/questions/8789729/zero-padding-in-bash
沒有留言:
張貼留言