Arithmetic Expansion in Shell Programming

Arithmetic expansion, arithmetic expansion, is of the form:

$((math expression))

One article seems to say ( here ) that backticks used to be used, but double brackets are used now.

In mathematical expressions, unlike the rest of the shell:

1. Spaces can be used, and spaces will be ignored.

echo $(( a = i + 8))

echo $(( 2#100 )) //Display binary 100, the result is 4

echo $(( 8#100)) //Display octal 100, the result is 64

2. A variable that is not assigned a value is not Null and is treated as 0.

 echo $(( i + 3)) //result is 3

3. There is a let tool available.

flight z = z + 3

let "z = z + 3" //Add a double quote, you can also add a space. But unassigned variables will be treated as null

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325469169&siteId=291194637