Bash Reference Manual Reference Documentation for Bash



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

Chapter 3: Basic Shell Features
7
\e
\E
an escape character (not ANSI C)
\f
form feed
\n
newline
\r
carriage return
\t
horizontal tab
\v
vertical tab
\\
backslash
\’
single quote
\"
double quote
\?
question mark
\nnn
the eight-bit character whose value is the octal value nnn (one to three digits)
\xHH
the eight-bit character whose value is the hexadecimal value HH (one or two
hex digits)
\uHHHH
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
HHHH (one to four hex digits)
\UHHHHHHHH
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
HHHHHHHH (one to eight hex digits)
\cx
a control-x character
The expanded result is single-quoted, as if the dollar sign had not been present.
3.1.2.5 Locale-Specific Translation
A double-quoted string preceded by a dollar sign (‘$’) will cause the string to be translated
according to the current locale. If the current locale is C or POSIX, the dollar sign is ignored.
If the string is translated and replaced, the replacement is double-quoted.
Some systems use the message catalog selected by the LC_MESSAGES shell variable. Others
create the name of the message catalog from the value of the TEXTDOMAIN shell variable,
possibly adding a suffix of ‘.mo’. If you use the TEXTDOMAIN variable, you may need to set
the TEXTDOMAINDIR variable to the location of the message catalog files. Still others use both
variables in this fashion: TEXTDOMAINDIR/LC_MESSAGES/LC MESSAGES/TEXTDOMAIN.mo.
3.1.3 Comments
In a non-interactive shell, or an interactive shell in which the interactive_comments option
to the shopt builtin is enabled (see Section 4.3.2 [The Shopt Builtin], page 64), a word
beginning with ‘#’ causes that word and all remaining characters on that line to be ignored.
An interactive shell without the interactive_comments option enabled does not allow
comments. The interactive_comments option is on by default in interactive shells. See
Section 6.3 [Interactive Shells], page 85, for a description of what makes a shell interactive.


Chapter 3: Basic Shell Features
8
3.2 Shell Commands
A simple shell command such as echo a b c consists of the command itself followed by
arguments, separated by spaces.
More complex shell commands are composed of simple commands arranged together in
a variety of ways: in a pipeline in which the output of one command becomes the input of
a second, in a loop or conditional construct, or in some other grouping.
3.2.1 Simple Commands
A simple command is the kind of command encountered most often. It’s just a sequence of
words separated by blanks, terminated by one of the shell’s control operators (see Chapter 2
[Definitions], page 3). The first word generally specifies a command to be executed, with
the rest of the words being that command’s arguments.
The return status (see Section 3.7.5 [Exit Status], page 39) of a simple command is its
exit status as provided by the posix 1003.1 waitpid function, or 128+n if the command
was terminated by signal n.
3.2.2 Pipelines
A pipeline is a sequence of one or more commands separated by one of the control operators
‘|’ or ‘|&’.
The format for a pipeline is
[time [-p]] [!] command1 [ | or |& command2 ] ...
The output of each command in the pipeline is connected via a pipe to the input of the next
command. That is, each command reads the previous command’s output. This connection
is performed before any redirections specified by the command.
If ‘|&’ is used, command1’s standard error, in addition to its standard output, is con-
nected to command2’s standard input through the pipe; it is shorthand for 2>&1 |. This
implicit redirection of the standard error to the standard output is performed after any
redirections specified by the command.
The reserved word time causes timing statistics to be printed for the pipeline once it
finishes. The statistics currently consist of elapsed (wall-clock) time and user and system
time consumed by the command’s execution. The -p option changes the output format to
that specified by posix. When the shell is in posix mode (see Section 6.11 [Bash POSIX
Mode], page 96), it does not recognize time as a reserved word if the next token begins
with a ‘-’. The TIMEFORMAT variable may be set to a format string that specifies how the
timing information should be displayed. See Section 5.2 [Bash Variables], page 71, for a
description of the available formats. The use of time as a reserved word permits the timing
of shell builtins, shell functions, and pipelines. An external time command cannot time
these easily.
When the shell is in posix mode (see Section 6.11 [Bash POSIX Mode], page 96), time
may be followed by a newline. In this case, the shell displays the total user and system time
consumed by the shell and its children. The TIMEFORMAT variable may be used to specify
the format of the time information.
If the pipeline is not executed asynchronously (see Section 3.2.3 [Lists], page 9), the shell
waits for all commands in the pipeline to complete.


Chapter 3: Basic Shell Features
9
Each command in a pipeline is executed in its own subshell (see Section 3.7.3 [Command
Execution Environment], page 37). The exit status of a pipeline is the exit status of the
last command in the pipeline, unless the pipefail option is enabled (see Section 4.3.1 [The
Set Builtin], page 60). If pipefail is enabled, the pipeline’s return status is the value of
the last (rightmost) command to exit with a non-zero status, or zero if all commands exit
successfully. If the reserved word ‘!’ precedes the pipeline, the exit status is the logical
negation of the exit status as described above. The shell waits for all commands in the
pipeline to terminate before returning a value.
3.2.3 Lists of Commands
A list is a sequence of one or more pipelines separated by one of the operators ‘;’, ‘&’,
‘&&’, or ‘||’, and optionally terminated by one of ‘;’, ‘&’, or a newline.
Of these list operators, ‘&&’ and ‘||’ have equal precedence, followed by ‘;’ and ‘&’, which
have equal precedence.
A sequence of one or more newlines may appear in a list to delimit commands, equiv-
alent to a semicolon.
If a command is terminated by the control operator ‘&’, the shell executes the command
asynchronously in a subshell. This is known as executing the command in the background.
The shell does not wait for the command to finish, and the return status is 0 (true). When
job control is not active (see Chapter 7 [Job Control], page 100), the standard input for
asynchronous commands, in the absence of any explicit redirections, is redirected from
/dev/null.
Commands separated by a ‘;’ are executed sequentially; the shell waits for each command
to terminate in turn. The return status is the exit status of the last command executed.
and and or lists are sequences of one or more pipelines separated by the control oper-
ators ‘&&’ and ‘||’, respectively. and and or lists are executed with left associativity.
An and list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
An or list has the form
command1 || command2
command2 is executed if, and only if, command1 returns a non-zero exit status.
The return status of and and or lists is the exit status of the last command executed
in the list.
3.2.4 Compound Commands
Compound commands are the shell programming constructs. Each construct begins with
a reserved word or control operator and is terminated by a corresponding reserved word
or operator. Any redirections (see Section 3.6 [Redirections], page 32) associated with
a compound command apply to all commands within that compound command unless
explicitly overridden.
In most cases a list of commands in a compound command’s description may be separated
from the rest of the command by one or more newlines, and may be followed by a newline
in place of a semicolon.


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ə