In shell, what is the use of quotation marks ($ & quot; string & quot; and $ & #39; string & #39;), shellstring

Source: Internet
Author: User

In shell, what is the use of quotation marks ($ "string" and $ 'string') and shellstring?

Sometimes you can see $ "$ string" in some service management scripts. After some tests, it is found that $ is the same as $ outside the quotation marks. I flipped through man bash and found an explanation.

(1). If you do not have a specially customized bash environment or have special requirements, $ "string" is equivalent to "string". use $ "to ensure localization.

Here is man bash's explanation of $:

       A  double-quoted  string  preceded by a dollar sign ($"string") 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.

(2 ). there is also $ followed by single quotes $ 'string', which is specially treated in bash: Some backslash sequences (such as \ n, \ t) escape without being considered as a literal (if there is no $ symbol, the single quotation mark forcibly translates the string into a literal, including a backslash ). Simple Example:

[root@xuexi ~]# echo 'a\nb'a\nb[root@xuexi ~]# echo $'a\nb'ab

Here is a description of $ in man bash:

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              \e              \E     an escape character              \f     form feed              \n     new line              \r     carriage return              \t     horizontal tab              \v     vertical tab              \\     backslash              \'     single quote              \"     double quote              \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

 

Back to Linux series article outline: http://www.cnblogs.com/f-ck-need-u/p/7048359.html
Back to website architecture series article outline: http://www.cnblogs.com/f-ck-need-u/p/7576137.html
Back to database series article outline: http://www.cnblogs.com/f-ck-need-u/p/7586194.html
Reprinted please indicate the source: http://www.cnblogs.com/f-ck-need-u/p/8451982.html

Note: If you think this article is not bad, please click the recommendation in the lower right corner. Your support can stimulate the author's enthusiasm for writing. Thank you very much!

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.