If there are some special characters in the shell, you need to replace them, you can do command substitution, variable substitution, escape substitution
1. Substitution of escape characters
The shell contains the following transfer characters
\a Bell alarm \ \ Backslash
\b Backspace (delete key)
\f (FF), moves the current position to the beginning of the next page
\ nthe line break
\ r Enter
\ t Horizontal tab
\v Vertical Tab
The above transfer characters can be used in echo, by using-E to complete the replacement of the escape character, the person will be output as-is, or through-e prohibit the transfer, through-n can prohibit inserting line break
2. Command replacement
The following declaration assigns the command date to date, noting that the command here must be extended with an inverted parenthesis instead of a single quote
1 [email protected] ~/shell2 $ date= 'DATE'34 [email Protected] ~/shell5echo $DATE6: -
3. Variable substitution
Variable substitution is based on whether it is empty, whether it is defined, and the value of the variable can be changed
Alternate form of a variable:
Form |
Description |
${var} |
The variable's original value |
${var:-word} |
If the variable var is empty or has been deleted (unset), it returns word, but does not change the value of Var |
${var:=word} |
If the variable var is empty or has been deleted (unset), return to Word and set the value of Var to Word |
${var:?message} |
If the variable var is empty or has been deleted (unset), the message messages are sent to the standard error output, which can be used to detect whether Var can be assigned to a normal value. If this substitution appears in the shell script, the script will stop running |
${var:+word} |
If the variable var is defined, then return to word, but do not change the value of Var |
|
|
PostScript: None
Replacement in the shell