我有一组循环记录.这个号码的范围从0000001到0089543,可以调用UIDX.
如果我尝试类似的东西:
for ((i=0; i< 0089543; i++)); do ((UIDX++)) done
计数器增量1,2,3,4,而不是我需要的0000001,0000002 ……
什么是填补领先零的最佳方式?
使用printf命令格式化带有前导零的数字,例如:
原文链接:https://www.f2er.com/bash/384601.htmlfor ((i = 0; i < 99; ++i)); do printf -v num '%07d' $i; echo $num; done
来自man bash:
printf [-v var] format [arguments] Write the formatted arguments to the standard output under the control of the format. The -v option causes the output to be assigned to the variable var rather than being printed to the standard output.