# Problem in incrementin a variable in UNIX shell script

**URL:** <https://community.unix.com/t/problem-in-incrementin-a-variable-in-unix-shell-script/175635>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [September 17, 2007, 6:02am UTC](https://community.unix.com/t/problem-in-incrementin-a-variable-in-unix-shell-script/175635 "2007-09-17T06:02:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![communicator](https://community.unix.com/letter_avatar/communicator/32/6_449c533f586939b6e5f246632a46421f.png) [@communicator](https://community.unix.com/u/communicator)\
**Post date:** [September 17, 2007, 6:02am UTC](https://community.unix.com/t/problem-in-incrementin-a-variable-in-unix-shell-script/175635/1 "2007-09-17T06:02:49Z")

</div>

I have a simple query  
If we have BATCH= 081675  
and incremnting it by one as  
BATCH=`expr ${BATCH} + 000001`;

We can't get BATCH = 081676  
but gets BATCH = 81676

Can anyone tell why i am getting this value and not the rquired one and how i could get the required one?

---

<div class="post-metadata">

**Author:** ![robotronic](https://community.unix.com/user_avatar/community.unix.com/robotronic/32/57_2.png) [@robotronic](https://community.unix.com/u/robotronic)\
**Post date:** [September 17, 2007, 3:49pm UTC](https://community.unix.com/t/problem-in-incrementin-a-variable-in-unix-shell-script/175635/2 "2007-09-17T15:49:16Z")

</div>

Because you are operating with integers, not with strings.  
I suggest you to perform all the computations with integers and, only at the end, pad the result with the required zeroes (in this case, 6 zeroes):

```nohighlight
BATCH=081675
BATCH=`expr ${BATCH} + 1`
BATCH=`printf "%06d\n" "$BATCH"`
echo "$BATCH"

```
