Dheeban Chakkaravarthy
Dheeban Chakkaravarthy

Reputation: 249

Adding two numbers with zero padding in bash shell

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

Expected result: 00002

Actual result: 2

How can I get the expected result in Bash?

Upvotes: 2

Views: 119

Answers (1)

Jahid
Jahid

Reputation: 22438

You can do this:

printf "%05d\n" $(expr $var1 + $var2)

Upvotes: 4

Related Questions