Variable permutation command permutation formula substitution reference use backslash implementation reference use single quotation marks with double quotes
variable Substitution
There are four forms of substitution for variable permutations
Syntax format: ${param:=word}
If the Param value is empty or unassigned, word replaces param as the return value of the expression, but does not change the value of param
Examples are as follows:
It is clear that the value of the myfruit variable is still empty and the value of the fruit variable becomes the Apple default value assignment
Syntax format: ${param:=word}
If the Param value is empty or unassigned, Word assigns its own value to Param
Examples are as follows:
Null value error
Syntax format: ${param:?msg}
When the variable param is unassigned or empty, an error message is printed. MSG to stderr
Examples are as follows:
a value substitution
Syntax format: ${param:+word}
If the variable param has a value, the variable word replaces Param as the return value of the expression, but the Param value is unchanged
Examples are as follows:
command Substitution
is to assign the output of a command to a variable as the value of a variable
Example:
Me? You can also direct the command substitution as an argument to another command:
Formula substitution
can help users complete basic integer operations in the shell
Syntax format $ ((expr))
Reference To implement a reference using a backslash
In fact, this backslash is to play an escape function, so that the characters with special meaning invalidation
The reference is escaped and there is no more to repeat here using single quotes
For an echo statement that contains many special characters, we can directly use single quotes to cause the statement to be output.
Use double quotes
The limitation of using single quotes is great, it escapes all the special symbols, which is not the problem with double quotes, and double quotes prohibit all metacharacters except $ and ' , and the commands that use inverted quotes ' are normally executed: