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.
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?
month=02
month=3
month=03
even when I add
month=`expr $month + 01`
it doesn't work.
使用printf:
printf
$ month=1 $ printf "%02d" $month 01
这种方法适用于month两位数的数字。
month
$ month=11 $ printf "%02d" $month 11
[你也可以通过说来增加一个变量let month++。]
let month++