Bash Reference Manual Reference Documentation for Bash



Yüklə 4,8 Kb.
Pdf görüntüsü
səhifə4/66
tarix08.10.2017
ölçüsü4,8 Kb.
#3723
1   2   3   4   5   6   7   8   9   ...   66

4
return status
A synonym for exit status.
signal
A mechanism by which a process may be notified by the kernel of an event
occurring in the system.
special builtin
A shell builtin command that has been classified as special by the posix stan-
dard.
token
A sequence of characters considered a single unit by the shell. It is either a
word or an operator.
word
A sequence of characters treated as a unit by the shell. Words may not include
unquoted metacharacters.


5
3 Basic Shell Features
Bash is an acronym for ‘Bourne-Again SHell’. The Bourne shell is the traditional Unix shell
originally written by Stephen Bourne. All of the Bourne shell builtin commands are available
in Bash, The rules for evaluation and quoting are taken from the posix specification for the
‘standard’ Unix shell.
This chapter briefly summarizes the shell’s ‘building blocks’: commands, control struc-
tures, shell functions, shell parameters, shell expansions, redirections, which are a way to
direct input and output from and to named files, and how the shell executes commands.
3.1 Shell Syntax
When the shell reads input, it proceeds through a sequence of operations. If the input
indicates the beginning of a comment, the shell ignores the comment symbol (‘#’), and the
rest of that line.
Otherwise, roughly speaking, the shell reads its input and divides the input into words
and operators, employing the quoting rules to select which meanings to assign various words
and characters.
The shell then parses these tokens into commands and other constructs, removes the
special meaning of certain words or characters, expands others, redirects input and output
as needed, executes the specified command, waits for the command’s exit status, and makes
that exit status available for further inspection or processing.
3.1.1 Shell Operation
The following is a brief description of the shell’s operation when it reads and executes a
command. Basically, the shell does the following:
1. Reads its input from a file (see Section 3.8 [Shell Scripts], page 40), from a string
supplied as an argument to the -c invocation option (see Section 6.1 [Invoking Bash],
page 82), or from the user’s terminal.
2. Breaks the input into words and operators, obeying the quoting rules described in
Section 3.1.2 [Quoting], page 6. These tokens are separated by metacharacters. Alias
expansion is performed by this step (see Section 6.6 [Aliases], page 90).
3. Parses the tokens into simple and compound commands (see Section 3.2 [Shell Com-
mands], page 8).
4. Performs the various shell expansions (see Section 3.5 [Shell Expansions], page 21),
breaking the expanded tokens into lists of filenames (see Section 3.5.8 [Filename Ex-
pansion], page 30) and commands and arguments.
5. Performs any necessary redirections (see Section 3.6 [Redirections], page 32) and re-
moves the redirection operators and their operands from the argument list.
6. Executes the command (see Section 3.7 [Executing Commands], page 36).
7. Optionally waits for the command to complete and collects its exit status (see
Section 3.7.5 [Exit Status], page 39).


Chapter 3: Basic Shell Features
6
3.1.2 Quoting
Quoting is used to remove the special meaning of certain characters or words to the shell.
Quoting can be used to disable special treatment for special characters, to prevent reserved
words from being recognized as such, and to prevent parameter expansion.
Each of the shell metacharacters (see Chapter 2 [Definitions], page 3) has special meaning
to the shell and must be quoted if it is to represent itself. When the command history
expansion facilities are being used (see Section 9.3 [History Interaction], page 139), the
history expansion character, usually ‘!’, must be quoted to prevent history expansion. See
Section 9.1 [Bash History Facilities], page 137, for more details concerning history expansion.
There are three quoting mechanisms: the escape character, single quotes, and double
quotes.
3.1.2.1 Escape Character
A non-quoted backslash ‘\’ is the Bash escape character. It preserves the literal value of
the next character that follows, with the exception of newline. If a \newline pair appears,
and the backslash itself is not quoted, the \newline is treated as a line continuation (that
is, it is removed from the input stream and effectively ignored).
3.1.2.2 Single Quotes
Enclosing characters in single quotes (‘’’) preserves the literal value of each character within
the quotes. A single quote may not occur between single quotes, even when preceded by a
backslash.
3.1.2.3 Double Quotes
Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within
the quotes, with the exception of ‘$’, ‘‘’, ‘\’, and, when history expansion is enabled, ‘!’.
When the shell is in posix mode (see Section 6.11 [Bash POSIX Mode], page 96), the ‘!’
has no special meaning within double quotes, even when history expansion is enabled. The
characters ‘$’ and ‘‘’ retain their special meaning within double quotes (see Section 3.5
[Shell Expansions], page 21). The backslash retains its special meaning only when followed
by one of the following characters: ‘$’, ‘‘’, ‘"’, ‘\’, or newline. Within double quotes,
backslashes that are followed by one of these characters are removed. Backslashes preceding
characters without a special meaning are left unmodified. A double quote may be quoted
within double quotes by preceding it with a backslash. If enabled, history expansion will
be performed unless an ‘!’ appearing in double quotes is escaped using a backslash. The
backslash preceding the ‘!’ is not removed.
The special parameters ‘*’ and ‘@’ have special meaning when in double quotes (see
Section 3.5.3 [Shell Parameter Expansion], page 23).
3.1.2.4 ANSI-C Quoting
Words of the form $’string’ are treated specially. The word expands to string, with
backslash-escaped characters replaced as specified by the ANSI C standard. Backslash
escape sequences, if present, are decoded as follows:
\a
alert (bell)
\b
backspace


Yüklə 4,8 Kb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   ...   66




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə