A=1b=2letc=a+becho $c
View Code
Let a++b+ +echo $a $b
View Code
A=1b=2echo $[a+b]echo $[$a + $b]
View Code
A=1b=2echo $ ((a+b))
View Code
A=1b=2C=$ (expr $a +$b)echo $c
View Code
Note: The above four methods are only for integer operations, if the floating-point operation to use the BC This advanced tool
[Email protected]:~$ num1=1.1[email protected]-pc:~$ num2=2.2[email protected]-pc:~$ num3= 'Echo "$num 1 * $num 2"|BC ' [email protected]-pc:~$Echo$num 32.4[email protected]-pc:~$ # Set decimal precision with scale parameter [email protected]-pc:~$ num3= 'Echo "scale=7, $num 1 * $num 2"|BC ' [email protected]-pc:~$Echo$num 32.42[email protected]-pc:~$ # using BC for carry-on conversion [email protected]-pc:~$ # decimal goto binary [email protected]-pc:~$ num=123[email protected]-pc:~$ result= 'Echo "obase=2; $num"|BC ' [email protected]-pc:~$Echo$result1111011[email protected]-pc:~$ # binary goto decimal [email protected]-pc:~$Echo "obase=10;ibase=2; $result"|BC123[email protected]-pc:~$ # uses BC to calculate square and square root [email protected]-pc:~$Echo "sqrt (+)"|BCTen[email protected]-pc:~$Echo "10^10"|BC10000000000[email protected]-pc:~$
View Code
Linux Math Operations