variables and environment variables
Var=value assigns a value to the variable, the output statement: $ echo $var or $ echo ${var}, remember that there is a space in the middle
For example: Name= "Coffee" age= "$echo" my name is : ${name}, The age is : ${age} " in the output statement Echo You can use a variable in double quotes , But the variable does not extend the defined value if it is a single quotation mark.
Gets the length of the string: ${#var}
1 // /For example:2 name="yy"$echo ${#name} 3 //The result of the output is 2.
View Code
or $SHELL can get the kind of shell that's currently in use , note:Shell all letters must be in uppercase
The Export command sets the environment variable, after which the current Shell script inherits the value of the variable .
Some common environment variables:HOME PWD USER UID SHELL
UID: Check current script user identity,root user uid is 0
Shell: The type of the current shell
Mathematical Operations
the Let command is a simple arithmetic operation that can be used without adding $ before the variable name
For example:
Self-add operation:$ let one++
Self-subtraction:$ let two--
It is also possible to abbreviate:$ let one+=2 $ let two-=1 respectively equal to $ let one = one + 2 and $ let two = Two-1
The operator [] also has a function similar to the Let command
You can also use (()), but note that you need to add $before the variable name, or you will get an error.
The above method is only suitable for operations between integers, and does not support decimals.
Real life without decimals that is almost impossible, of course, the Shell is not so simple,theBC command is a high-level mathematical arithmetic tool that performs floating-point arithmetic and applies some advanced functions:
Set decimal Precision scale command, no effect on multiplication (*) operation
Convert obase ( output binary ) and ibase ( input-to- binary ) commands between binary
Computes the square, square root sqrt command
Note: If you do not have the square root, then the result is the maximum value that is smaller than the original value.
Play change volume, environment variables, and math operations (shell)