Metacharacters
Certain characters have special meaning to the shell. These are known as metacharacters. They are listed below.
Pattern Matching:
This set of metacharacters is used in pattern matching, also known as wild cards.
* Match zero or more characters
? match exactly one character
[] Match a list or range of characters eg [AB], [A-N]
[!] Match anything except the list or range of characters e.g. [!AB]
Redirection:
> Redirect away from the standard output file
>> Redirect away from the standard output and append to the target file
2> Redirect away from the standard error file
< redirect away from the standard input file
<< Start of a Here document
| Pipe the output of one command to the input of a second command
Miscellaneous
& Run the command in the background
() Execute command(s) in sub-shell
$ Substitute the value of a variable or argument
# ignore text to end of line
; New line
: Null command
Literal
\ take the literal of the following character – this is used to include an actual metacharacter in a string, rather than have the shell try to interpret it e.g.\$
‘’ Interpret all characters enclosed in single quotes as a literal
“” Interpret all characters enclosed in double quotes as a literal, except the dollar sign.
Literals are important, since without them, the shell will first interpret any metacharacters before working with the string. For example, the following command would produce an error:
echo Enter your name>
since the > would be interpreted as a redirection symbol. This can be avoided by placing the text in quotes:
echo ‘Enter your name>’