2
var1=00001 var2=00001 expr $var1 + $var2 

Expected result: 00002

Actual result: 2

How can I get the expected result in Bash?

2
  • Do you always get 5 digits? Commented Jan 28, 2016 at 12:48
  • yes. i want always 5 digits Commented Jan 28, 2016 at 12:59

1 Answer 1

4

You can do this:

printf "%05d\n" $(expr $var1 + $var2) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.