Today, Xiaobai suddenly wanted to use the shell to find the 32 power of 2, but couldn’t find a solution. After searching on the Internet, I found it was very simple, as follows:

[email protected]:~> Echo “2**32” | bc-l # thus it can be obtained that BC does not support the power solution

(standard_in) 1: syntax error

Method 1:

[email protected]:~> let “2**32”

[email protected]:~> let “y=2**32”

[email protected]:~> echo $y

4294967296

Method 2:

[email protected]:~> echo $[2**32]

4294967296

1. Summarize the operator in the shell:

+ : add two variables.

– : subtract two variables.

* : multiply two variables.

/: divide two variables.

** : power two variables.

% : modulus operation, the first variable divided by the second variable to find the remainder.

+= : plus equals, add a second variable on top of itself.

-= : minus is equal to, subtract the second variable from the first variable.

*= : multiply by equals, multiplying by the second variable from the first.

/= : division is equal to, on the basis of the first variable divided by the second variable.

%= : take module assignment, the first variable takes module operation on the second variable, and then assigns value to the first variable.

2. Common operation commands:

A. Use lets to indicate mathematical operations. You can first assign the result of the operation to the variable B. The operation command is B =let 1 + 2. Echo $b is then used to output the value of B. If there is no let, it outputs 1+2.

B. Use $[] to express the mathematical operation. Writes a mathematical operation to the $[] bracket, and the contents of the bracket are mathematically performed first. For example, the command echo $[1+2] will output the result 3.

C. Use EXPR to change the order of operations. Echo ‘expr 1+2’ can be used to output the result of 1+2, using expr to represent the following expression as a mathematical operation. Note that ‘is not a single quotation mark, but the symbol above the “Tab” key.

d. BC for mathematical operations. You can use it in conjunction with the echo command, for example: echo “3.21*2” | BC to calculate the 3.21*2 floating-point operation

E. Use AWK for mathematical commands. Echo 2 | awk ‘{print $1**32}’

[email protected]:~> Echo “2**32” | bc-l # thus it can be obtained that BC does not support the power solution

(standard_in) 1: syntax error

Method 1:

[email protected]:~> let “2**32”

[email protected]:~> let “y=2**32”

[email protected]:~> echo $y

4294967296

Method 2:

[email protected]:~> echo $[2**32]

4294967296

1. Summarize the operator in the shell:

+ : add two variables.

– : subtract two variables.

* : multiply two variables.

/: divide two variables.

** : power two variables.

% : modulus operation, the first variable divided by the second variable to find the remainder.

+= : plus equals, add a second variable on top of itself.

-= : minus is equal to, subtract the second variable from the first variable.

*= : multiply by equals, multiplying by the second variable from the first.

/= : division is equal to, on the basis of the first variable divided by the second variable.

%= : take module assignment, the first variable takes module operation on the second variable, and then assigns value to the first variable.

2. Common operation commands:

A. Use lets to indicate mathematical operations. You can first assign the result of the operation to the variable B. The operation command is B =let 1 + 2. Echo $b is then used to output the value of B. If there is no let, it outputs 1+2.

B. Use $[] to express the mathematical operation. Writes a mathematical operation to the $[] bracket, and the contents of the bracket are mathematically performed first. For example, the command echo $[1+2] will output the result 3.

C. Use EXPR to change the order of operations. Echo ‘expr 1+2’ can be used to output the result of 1+2, using expr to represent the following expression as a mathematical operation. Note that ‘is not a single quotation mark, but the symbol above the “Tab” key.

d. BC for mathematical operations. You can use it in conjunction with the echo command, for example: echo “3.21*2” | BC to calculate the 3.21*2 floating-point operation

E. Use AWK for mathematical commands. Echo 2 | awk ‘{print $1**32}’

### Read More:

- An undetermined call to function ‘shell’: missing ‘. Stop. Problem encountered when using shell command in makefile
- Common shell (1): shell gets the current time stamp of the system
- In Linux shell script, about the commonly used flag [- EQ, GT..] in test and if judgment
- The method of getting shell command output in Python
- Several methods of executing multiple commands in Linux shell
- Linux shell loop in a line for while
- how to clear screen in python shell
- Linux shell RM deletes all. O suffix files in the subdirectory
- Adding prefixes to file names in batch by shell under mac
- Invalid host header error in Vue using peanut shell agent
- Linux’s method of clearing DNS cache and refreshing DNS in shell terminal (Ubuntu, Debian)
- PySpark ERROR Shell: Failed to locate the winutils binary in the hadoop binary path
- The list command in HBase shell reported an error org.apache.hadoop . hbase.PleaseHoldException : Master is initializing
- The difference between single equal sign and double equal sign EQ in shell script
- Linux shell gets the file name under the folder
- Solve the problem of Vue running error（ process.env.NODE_ Env = =’production ‘) and error in plugin “gulp shell”“
- Shell script syntax error near unexpected token ‘$’Do
- Shell removes double quotes from strings
- Removing duplicate lines from Linux shell files
- The shell gets the current time of the system and formats it