[英]Why does the first bash var work but not the other? Trying to increment string ints
Where it worked...它在哪里工作...
tt=0000005
echo $((tt))
tt=$(($tt+1))
echo $((tt))
5 5
6 6
Somewhere it stopped working...它在某个地方停止工作......
tt=0056505
echo $((tt))
tt=$(($tt+1))
echo $((tt))
23877 23877
23878 23878
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.