[Bash]整型变量自增(加1)的几种方法

#note that any space is not allowed before nor after =
#you can use or not use $ before a variable inside $(()) and $[]
a=1
a=$((a+1))
a=$((a + 1))
a=$(( a + 1 ))
a=$(( $a + 1 ))

a=$[a+1]
a=$[a + 1]
a=$[ a + 1 ]
a=$[ $a + 1 ]

#note that a space is required before and after +
a=`expr $a + 1`

let a++
let a+=1
#the result will be 12
echo $a   

猜你喜欢

转载自my.oschina.net/u/553266/blog/2933926
今日推荐