1

If I have a variable as

month=02 and when I add one to it as month=`expr $month + 1` then it becomes month=3 but I want it to be month=03 what shall I do for this?

even when I add

month=`expr $month + 01`

it doesn't work.

4

1 回答 1

2

使用printf

$ month=1
$ printf "%02d" $month
01

这种方法适用于month两位数的数字。

$ month=11
$ printf "%02d" $month
11

[你也可以通过说来增加一个变量let month++。]

于 2013-08-12T12:21:20.797 回答