Bash supports many operators, including arithmetic operators, relational operators, Boolean operators, string operators, and file test operators.
Native bash does not support simple math operations, but can be implemented with other commands, such as awk and expr,expr, which are most commonly used.
Native bash support does not support mathematical calculations I'm not sure, but it does the same thing:
#!/bin/bashval22))echo'total value:' $valval 2 2 ]echo'total value:'$val
I think the current version of Bash native is supported by compute
Expr is an expression evaluation tool that uses it to perform evaluation operations on expressions.
For example, two numbers are added:
#!/bin/bashval=$ (expr22)echo'total value: '$val
Run the script output:
Total Value:4
Two points Note:
- There are spaces between the expression and the operator, such as the 2 + 2, which is different from most of the programming languages we are familiar with.
- The complete expression is to be contained, note that this character is not a common single quote, below the ESC key.
Arithmetic operators
Let's take a look at an example that uses arithmetic operators:
Shell operators: Shell arithmetic operators, relational operators, Boolean operators, string operators, and so on