| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 3.1.1 Shell Operation | The basic operation of the shell. | |
| 3.1.2 Quoting | How to remove the special meaning from characters. | |
| 3.1.3 Comments | How to specify comments. |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following is a brief description of the shell's operation when it reads and executes a command. Basically, the shell does the following:
metacharacters. Alias expansion is performed by this step
(see section Aliases).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 3.1.2.1 Escape Character | How to remove the special meaning from a single character. | |
| 3.1.2.2 Single Quotes | How to inhibit all interpretation of a sequence of characters. | |
| 3.1.2.3 Double Quotes | How to suppress most of the interpretation of a sequence of characters. | |
| 3.1.2.4 ANSI-C Quoting | How to expand ANSI-C sequences in quoted strings. | |
| 3.1.2.5 Locale-Specific Translation | How to translate strings into different languages. |
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 section Definitions) 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 (@pxref{History Interaction}), the history expansion character, usually `!', must be quoted to prevent history expansion. @xref{Bash History Facilities}, for more details concerning history expansion.
There are three quoting mechanisms: the escape character, single quotes, and double quotes.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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, `!'.
The characters `$' and ``'
retain their special meaning within double quotes (see section Shell Expansions).
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 Shell Parameter Expansion).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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:
\aalert (bell)
\bbackspace
\ean escape character (not ANSI C)
\fform feed
\nnewline
\rcarriage return
\thorizontal tab
\vvertical tab
\\backslash
\'single quote
\nnnthe eight-bit character whose value is the octal value nnn (one to three digits)
\xHHthe eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
\cxa control-x character
The expanded result is single-quoted, as if the dollar sign had not been present.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In a non-interactive shell, or an interactive shell in which the
interactive_comments option to the shopt
builtin is enabled (see section Bash Builtin Commands),
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 Interactive Shells, for a description of what makes
a shell interactive.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |