Section 5.5. Metacharacters


[Page 171 (continued)]

5.5. Metacharacters

Some characters are processed specially by the shell, and are known as metacharacters. All shells share a core set of common metacharacters, whose meanings are given in Figure 5-5.

Figure 5-5. Shell metacharacters.

[Page 172]

Symbol

Meaning

>

Output redirection; writes standard output to a file.

>>

Output redirection; appends standard output to a file.

<

Input redirection; reads standard input from a file.

*

File substitution wildcard; matches zero or more characters.

?

File substitution wildcard; matches any single character.

[...]

File substitution wildcard; matches any character between brackets.

`command`

Command substitution; replaced by the output from command.

|

Pipe symbol; sends the output of one process to the input of another.

;

Used to sequence commands.

| |

Conditional execution; executes a command if the previous one failed.

&&

Conditional execution; executes a command if the previous one succeeded.

(...)

Groups commands.

&

Runs a command in the background.

#

All characters that follow up to a newline are ignored by the shell and programs (i.e., a comment).

$

Expands the value of a variable.

\

Prevents special interpretation of the next character.

<<tok

Input redirection; reads standard input from script up to tok.



[Page 172]

When you enter a command, the shell scans it for metacharacters and processes them specially. When all metacharacters have been processed, the command is finally executed. To turn off the special meaning of a metacharacter, precede it by a \ character. Here's an example:

$ echo hi > file    ...store output of echo in "file". $ cat file          ...look at the contents of "file". hi $ echo hi \> file   ...inhibit > metacharacter. hi > file           ...> is treated like other characters. $ _                 ...and output comes to terminal instead 


This chapter describes the meaning of each metacharacter in the order listed in Figure 5-5.




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net