Published Book on Amazon
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1 | |
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2 |
출판된 한글판 도서
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상) | |
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하) |
Original Book Contents
10.1.3 Quoting Rule
10.1.3.1 Overview of Quoting Rule
Quoting is to enclose a string with quotation marks. The reason for doing this is to prevent the special characters from being reinterpreted or expanded by the Shell or Shell script when special characters are included in the string. For reference, "special character" refers to a character that can be interpreted differently from the meaning of a character. For example, the wildcard character "*" is a special character.
When referring to a variable within a string, it is usually good to enclose it in double quotes (" "). This maintains all special characters as it except $, ` ` (backquote), and \ (escape) so that they will not be reinterpreted. For example, if you quote a variable as in "$variable" and recognize $ as a special character, "$variable" is changed by that variable's value.
■ "abc" -- Double quote
-- $, \(escape), ` `(backquote) is treated as a special character
Single quotes ('') behaves similiarly like double quotes, but all special characters except ` ` (backquote) are interpreted literally. You may think of the single quotation mark (full quotation) as a more strict way than the double quotation mark (partial quotation). Therefore, if you use $ in single quotes, it is not regarded as a special character, so variable references do not occur. Also, \(escape) is recognized literally in single quotes, so if you try to use \(escape) in single quotes to put the single quotes themselves, you will not get the results you want.
■ ‘abc‘ --Single quote
-- $, \(escape) is not regarded as a special character, interpreted literally.
Backquote (``) is used when you want to use the result of executing a specific command.
■ ` ` -- Backquote
-- Command enclosed in ` ` is executed and replaced by the processing result.
10.1.3.2 \Escape Sequence
Escape sequence is used to represent characters that can not be represented by ordinary characters. The beginning of this character is represented by a character starting with "\" (backslash).
Also, to use an escape sequence, you must use "-e" option when running the Shell command.
Below is a list of predefined escape sequences:
■ \\ backslash
■ \a alert (BEL)
■ \b backspace
■ \c produce no further output
■ \e escape
■ \f form feed
■ \n new line
■ \r carriage return
■ \t horizontal tab
■ \v vertical tab