1. Variable and variable values (expanded)
If you need a variable name, use the variable name directly, or if you need a variable value, use the $ symbol. For example:
Export Path=/home/bin: $PATH
If you're not sure if you want the variable or expanded variable value, try expanding the next-generation expression to see what's wrong.
In general, where the lvalue is required (assigning values to variables) directly with the variable name, where the right value is required (the value of the variable) plus the $ symbol.
2. Variable assignment, do not add a space before and after the equal number.
3 Separating variables and suffixes:
${go}ing
4. Shell wildcard characters and quotation marks
4.1 No quotation marks
For example, LS *.*,shell will expand *. * to all files in the current directory and then pass it to LS.
4.2 Double Quotes
If you use LS "* *", the shell will pass *. * to Ls,ls and will tell you that there is no file whose filename is *. *
However, if the $ symbol is present in double quotes, the shell will still explain.
4.3 single quotation marks
Well, now even $ does not explain.
5. C-style expressions
#!/bin/bash
var=2 # The default variable type is string and cannot be directly mathematically operated
echo $ ((var * var)) # ((C stype expression)), put in two parentheses, you can add a space before and after the operator, take the variable value does not need $, the calculated new variable still with the $ reference to echo
echo $var # var value is still 2, unchanged. If the previous line is $ ((var++)), then this line is 3.
Linux shell Programming