Home > Software engineering >  Why does the first bash var work but not the other? Trying to increment string ints
Why does the first bash var work but not the other? Trying to increment string ints

Time:08-10

Where it worked...

tt=0000005

echo $((tt))

tt=$(($tt 1))

echo $((tt))

5

6

Somewhere it stopped working...

tt=0056505

echo $((tt))

tt=$(($tt 1))

echo $((tt))

23877

23878

CodePudding user response:

You need to trim the leading zeros first

$ tt=0056505
$ tt=$(echo $tt | sed 's/^[0]*//g')
$ echo $((tt))
56505
$ tt=$(($tt 1))
$ echo $((tt))
56506
  •  Tags:  
  • bash
  • Related