Arithmetic Operators shell

. 1 ! # / Bin / the bash
 2  # Example arithmetic operators
 . 3 A = 10 
. 4 B = 20 is 
. 5  
. 6 Val = A + `$ expr $ B`
 . 7 echo " A + B: Val $ "   # 30 
. 8  
. 9 Val =` A $ expr - $ B`
 10 echo " A - B: Val $ " # - 10 
. 11  
12 is Val = `expr $ A \ * $ # B` without escape character (\) being given: expr: syntax error
 13 is echo " A * B: Val $ " # 200 is 
14  
15 Val expr $ = `A /B` $
 16 echo " B / A: Val $ " # 0 
. 17  
18 is Val = `expr $ A% $ B`
 . 19 echo " B% A: Val $ " # 10 
20 is  
21 is  
22 is  IF [== $ A $ B ]
 23 is  the then
 24 echo " A is equal to B " 
25  Fi
 26 is  
27  IF ! [= $ A $ B] will be given when no space between and #b]: ./ test.sh: Line 27 : [: Missing `] '
 28  the then 
 29 echo " A not equal to B " 
30 be

 

Guess you like

Origin www.cnblogs.com/kaerxifa/p/11403618.html