Wildcard characters, metacharacters, escape characters in Linux
- Wildcard OFDM character escapes in Linux
- The composition of the shell command
- Wildcard characters
- Metacharacters Meta
- Escape character
- Example
- Reference
The composition of the shell command
Each of the character in each Linux command is one of the following two types:
-Literal: Plain plain text
-Reserved word: Wildcard, metacharacters, escape character
Wildcard characters
Wildcards are handled by the shell (not by the command statements involved). As a matter of fact, we don't see any of these wildcard characters in the shell commands, but it only appears in the "Parameters" of the command (it doesn't have to be in the command name or on the operator). When the Shell encounters a wildcard character in "parameters". The shell will use it as a path or a file name to search for possible matches on the disk: If a matching match exists, the substitution (path extension) is performed. Otherwise, the wildcard is passed as a normal character to the command, which is then processed by the command. in short, a wildcard is actually a kind of path extension that the shell implements. After the wildcard is processed, the shell completes the reorganization of the command before continuing with the reorganized command until the command is run.
Wildcards and regular expressions look very much alike. But in fact, it's just a special character of the shell.
*
: Match 0 or more characters
?
: Match Random one character
[list]
: Matches random single character in list
[!list]
: Matches random single characters in non-list
[a1-a3]
: matches a random character between A1 and A3. such as 0-9,a-z
{string1,string2,string3...}
: Match string1, or string2 or ... One of the strings
Metacharacters Meta
IFS
: <space><tab><enter>
One of the three components used to split word in command line
CR
: <enter>
generated, used to end a command line
=
: Assign Value
$
: Variable substitution
>
: stdout
<
: stdin
|
: Pipeline Command
&
: Redirect file descriptor, or run the command in the background
`
: Used to replace
()
: Place the command in nested Subshell or for operation or command substitution
{}
: To run a command in non-named function, or to define the scope of variable substitution
;
: At the end of a command. Ignore its return value, continue running scare a command
&&
: At the end of a command. If the return value is true. Continue running the next command
||
: At the end of a command, if the return value is False, continue running the next command
!
: Run a command from the history list
Escape character
When we want to turn off meta functionality. The escape character is used.
‘
(single-cited) hard quote, where all meta-quote are closed.
"
(dual-cited) soft quote, most of the meta-quote in soft are closed, but some meta functions (such as $) are preserved.
\
(backslash) escape, only a single meta immediately after the escape (caret) will be closed.
Meta:, inverse, dquote not closed $
`
. Backslash \
.
Example
? ~ LS- Dp*# files that start with PPictures Projects public? ~ A=b CThe #<space> was not closed. As IFS processing. Zsh:command not found:c? ~ a="B C" #<space> is turned off in ", use as normal character? ~Echo $AB C? ~ a="B dquote> cdquote>" #<enter> is turned off in "and is used as a normal character because command line does not get the CR character and therefore enters the second shell prompt (denoted by the > symbol). ? ~Echo $ABc? ~ a=b\ C# \ Make <space> function off, only when normal spaces are used? ~Echo ' $A ' # $ in squote feature off. Only for literal$A? ~Echo "$A" # $ in dquote function not closed for meta useB C? ~Echo\$A$A? ~
Reference
Http://www.cnblogs.com/chengmo/archive/2010/10/17/1853344.html
Http://bbs.chinaunix.net/thread-2076396-1-1.html
Wildcard characters, metacharacters, escape characters in Linux