What is the use of quotation marks ($ "string" and $ 'string') in shell ')
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 @ bkjia ~] # Echo 'a \ nb'
A \ nb
[Root @ bkjia ~] # Echo $ 'a \ nb'
A
B
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
This article permanently updates link: https://www.bkjia.com/Linux/2018-02/151002.htm