bash 整数对比
How to convert an integer into a string of many characters padded with 0s in bash.
To do this in C:
要在C中执行此操作:
sprintf(buffer, "%08d", n);
which convert integer n
to a 8-character string padded with leading 0s.
它将整数n
转换为由前导0填充的8个字符的字符串。
How to padding a integer with 0s in bash?
如何在bash中以0填充整数?
In bash, you can also use printf
在bash中,您也可以使用printf
For the previous example:
对于前面的示例:
str=$(printf "%08d" $n)
where $n is the integer and $str contains the converted string.
其中$ n是整数,$ str包含转换后的字符串。
Answered by anonymous.
匿名回答。
翻译自: https://www.systutorials.com/how-to-padding-a-integer-with-0s-in-bash/
bash 整数对比