In addition to ordinary characters in the shell, there are many characters with special meanings and functions.
1. Wildcard characters
* : string of any length
? : Matches any single character
[]: Matches any one of these characters, for example:[ABC] matches a or B or C, it can also mean [a- z], but '-' is just a normal character outside [] , * and ? It also becomes a normal character in [].
2. Quotation marks
Single quote ': called a strong reference or full reference, in ' ... ' All characters in are treated as ordinary characters, including ($) (\) ('), but ' cannot appear in ' ... ', or the shell cannot determine the starting position of the single quotation mark.
Double quotation mark ": called a weak reference or partial reference, in the" ... "In addition to ($) (\) (') reserved for its special purpose, the remainder of the word nonalphanumeric as ordinary character processing.
3. Annotation characters
# : Some shell interpreters beginning with # are skipped. except #!.
#!: followed by an executable program (interpreter) that executes this script, and #! must be in the first line of the script.
4. Curly Braces
There are many usages of {} in the shell, most commonly referred to as variable prototypes such as: ${var} (which is the recommended method for referencing variables)
Variable extension of curly braces:
${var} |
Take out the variable var value |
${var:-default} |
If Var is not defined, $default is used as its value |
${var:=default} |
If Var is not defined, or if the value is NULL, $default is used as its value |
${var+value} |
If Var is defined, the value is $value, otherwise an empty string |
${var:+value} |
If Var is defined and is not a null value, the value is $value, otherwise an empty string |
${var? MSG} |
If Var is not defined, print $msg |
${var:? MSG} |
If Var is not defined or unassigned, print $msg |
${! prefix*} ${[email protected]} |
Match all variables that start with prefix |
${#STR} |
Returns the length of the $STR |
${str:position} |
Extracting a string from a location $position |
${str:position:length} |
Extracting a string of length $length from the location $position |
${STR#SUBSTR} |
Search from the beginning of the variable $str, delete the shortest match $substr string |
${str# #SUBSTR} |
Search from the beginning of the variable $STR to delete the longest matched $substr string |
${STR%SUBSTR} |
Search from the end of the variable $STR to delete the shortest matched $substr string |
${STR%%SUBSTR} |
Search from the end of the variable $STR to delete the longest matched $substr string |
${str/substr/replace} |
Replace the first matching $substr with $replace |
${str//substr/replace} |
Replace all matching $substr with $replace |
${str/#SUBSTR/replace} |
If $str starts with $substr, the $replace is used instead of the matching $SUBSTR |
${str/%substr/replace} |
If the $str ends with $substr, the $replace is used instead of the matching $SUBSTR |
5. Wildcard extension : (possible to match multiple permutation combinations)
such as coordinates: {x1,x2,x3}{y1,y2,y3}
# echo {x1,x2,x3}{y1,y2,y3}x1y1 x1y2 x1y3 x2y1 x2y2 x2y3 x3y1 x3y2 x3y3
such as file name:
# Touch file_{1,2} # ls file_{1,2}file_1 file_2
6. Statement block
Curly braces are also used to construct statement blocks that are separated by carriage returns between statements
7. Control characters :(that is, the ctrl+key combination, used to modify the terminal or text display, "control characters can no longer be used in scripting, can only interact with the shell")
As table:
Ctrl+b |
Backspace but do not remove the preceding characters |
CTRL + C |
End current foreground job |
Ctrl+d |
Terminator, which can be used to exit the current shell or to end the current input |
Ctrl+g |
System output a beep |
Ctrl+h |
Backspace and remove the preceding characters |
Ctrl+l |
Clear the screen, as with the clear effect |
Ctrl+i |
Horizontal tab |
Ctrl+k |
Vertical tab |
Ctrl+j |
Another line |
Ctrl+m |
Enter |
CTRL + Z |
Suspending foreground jobs |
CTRL + V |
Manipulating Visual Block in vim |
Ctrl+u |
Remove all characters from the cursor to the beginning of the line |
8. Other
- Anti-quote ': command substitution, which is the same as $ (), that returns the execution result of the current command and assigns a value to the variable
- Position parameters:
- $: script name itself
- $, $2...${10}: First argument of script, second parameter .... Tenth parameter
- $#: Total number of variables.
- $*, [email protected]: Displays all the parameters.
- $?: The return value of the previous command's exit.
- $!: ID number of the last background process.
- Exclamation point: Usually a logical inverse, also used to perform a command in the history: for example:!100 "command with line number 100 in Hsitory"
Special characters in the shell