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!