我有一组循环记录.这个号码的范围从0000001到0089543,可以调用UIDX.
如果我尝试类似的东西:
for ((i=0; i< 0089543; i++)); do ((UIDX++)) done
计数器增量1,2,3,4,而不是我需要的0000001,0000002 ……
什么是填补领先零的最佳方式?
使用printf命令格式化带有前导零的数字,例如:
for ((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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。