bash re-talk: quoting

Source: Internet
Author: User

3.1.2 Quoting
-------------

* Menu:

* Escape Character::how to remove the special meaning from a single
Character.
* Single quotes::how to inhibit all interpretation of a sequence
of characters.
* Double Quotes::how to suppress most of the interpretation of a
Sequence of characters.
* Ansi-c quoting::how to expand ansi-c sequences in quoted strings.
* Locale 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 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 (*note definitions::) have special
Meaning to the shell and must are quoted if it is to represent itself.
When the command is expansion facilities is being used (*note
History Interaction::), the EXPANSION character, usually '! ',
Must is quoted to prevent expansion. *note Bash History
Facilities::, for more details concerning the history expansion.

There is three quoting Mechanisms:the ESCAPE CHARACTER, single
Quotes, and double quotes.

File:bash.info, Node:escape Character, Next:single Quotes, up:quoting

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 ' was treated as a line
Continuation (That's, it's removed from the input stream and
Effectively ignored).

File:bash.info, Node:single Quotes, next:double Quotes, Prev:escape Character, up:quoting

3.1.2.2 Single Quotes
.....................

enclosing characters in single quotes ("") preserves the literal value
of each character within the quotes. A single quote could not occur
Between single quotes, even if preceded by a backslash.

File:bash.info, Node:double Quotes, next:ansi-c quoting, Prev:single Quotes, up:quoting

3.1.2.3 Double Quotes
.....................

Enclosing characters in double quotes (' "') preserves the literal value
of any characters within the quotes, with th E exception of ' $ ', ' ',
' \ ', and, when the history expansion is enabled, '! '. The characters ' $ '
and ' ' retain their special meaning within double quotes (*note Shell
Expansions::). The backslash retains its special meaning if
followed by one of the following characters: ' $ ', ' ', ' ' ', ' \ ', or
' newline '. Within double quotes, backslashes that is followed by one
of these characters is removed. Backslashes preceding characters
without a special meaning is left unmodified. A Double quote May is
quoted within double quotes by preceding it with a backslash. If
Enabled, history expansion'll be performed unless a '! ' appearing in
double quotes is escaped using a Backslas H. The backslash preceding
the '! ' is not removed.

The special parameters ' * ' and ' @ ' has special meaning when
Double quotes (*note Shell Parameter Expansion::).

File:bash.info, Node:ansi-c quoting, Next:locale translation, Prev:double Quotes, up:quoting

3.1.2.4 Ansi-c quoting
......................

Words of the form ' $ ' STRING ' is treated specially. The word expands
To STRING, with backslash-escaped characters replaced as specified by
The ANSI C standard. Backslash escape sequences, if present, is
Decoded as follows:

' \a '
Alert (Bell)

' \b '
Backspace

' \e '
An escape character (not ANSI C)

' \f '
Form Feed

' \ n '
NewLine

' \ r '
Carriage return

' \ t '
Horizontal tab

' \v '
Vertical tab

' \ \ '
Backslash

' \ '
Single quote

' \nnn '
The eight-bit character whose value is the octal value NNN
Three digits)

' \xhh '
The eight-bit character whose value is the hexadecimal value HH
(one or both hex digits)

' \cx '
A control-x character

The expanded result is single-quoted, as if the dollar sign had not
been present.

File:bash.info, Node:locale translation, prev:ansi-c quoting, up:quoting

3.1.2.5 locale-specific Translation
...................................

A double-quoted string preceded by a dollar sign (' $ ') would cause the
String to is translated according to the current locale. If the
Current locale was ' 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, your 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.

bash re-talk: quoting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.