Quotingby Pigbrain

Quoting

  • 특정 기호가 가지는 의미가 변경된다
CharacterMeaning
;Command separator
&Background execution
()Command grouping
Pipe
< > & Redirection symbols
* ? [ ] ~ + - @ ! Filename metacharacters
" ' / Used in quoting other characters
`Command substitution
$Variable substitution (or command or arithmetic substitution)
#Start a comment that continues to the end of the line
space tab newlineWord separators
  • “…” : 아래 문자를 제외한 “와 “안에 있는 모든 것은 문자로 취급된다
    • $ : 변수에 할당된 값을 출력
    • ` : 명령어의 결과 값을 출력
    • ” : -
  • ‘…’ : ‘와 ‘안에 있는 모든 것은 문자로 취급되며 중간에 ‘를 포함할 수 없다
  • \ : \다음에 나오는 기호는 문자로 취급된다
  • $’…’ : ‘…‘와 비슷하지만 Escape Sequences가 처리된다

Escape Sequences

SequenceAvailabilityValue
\a All ASCII BEL (visual or audible alert)
\b All Backspace
\e All Escape
\E All Escape
\f All Formfeed
\n All Newline
\r All Carriage return
\t All Tab
\uHHHH All Unicode character HHHH
\v All Vertical tab
\xHHAll Hexadecimal value HH
\` $'...' Single quote
\" $'...' Double quote
\? $'...' Question mark
\\ $'...' Backslash

Example

prompt> echo 'Single quotes "protect" double quotes'
Single quotes "protect" double quotes

prompt> echo "Well, isn’t that \"special\"?"
Well, isn’t that "special"?

prompt> echo "You have `ls | wc -l` files in `pwd`"
You have 43 files in /home/bob	

prompt> echo "The value of \$x is $x"
The value of $x is 100	

prompt> echo $'A\tB'
A	B


참고

Published 15 March 2016