Last Updated: February 25, 2016
·
389
· Chao Yang

Bash integer expansion

How many ways bash can deal with integer expansion ? I only know 4 methods, I think there are more:
1. use let:

$ a=5
$ let b=a*6
  1. use expr:

    $ a=5
    $ b=`expr $a \* 6`
  2. use $[ ... ]:

    $ a=5
    $ b=$[ $a * 6 ]
  3. use $(()):

    $ a=5
    $ b=$(( a * 6 ))
  • in method 1 and 4, the variable a is "NAKED".