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.

1 Answer 1

2

Use printf:

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

This approach would work when month is double-digit number.

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

[You can also increment a variable by saying let month++.]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.