Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在用 bash 做这样的事情
number=1 while [ $number -le 10 ]; do echo $number number=$((number+1)) done
这将输出:
1 2 3 4 5 6 7 8 9 10
.
如果我想要整数的总位数为 2,我该怎么办。如果整数的位数少于两位,则在左侧填充零。换句话说,我想要这样的输出:
01 02 03 04 05 06 07 08 09 10
有人知道如何管理这个吗?谢谢:)
使用printf代替echo:
printf
echo
printf "%02d\n" $number