Skip to content
Search

Quoting

lastmod 2018-08-17created 2015-11-196 edits

Quoting means enclosing a string in quotation marks. The reason for doing this is to prevent special characters inside the string from being reinterpreted or expanded by the shell or a shell script. (A character that can be interpreted differently from its literal meaning is called a special character. For example, the wildcard character * is a special character.)

When referencing a variable, it is usually best to enclose it in double quotes (" "). This preserves all special characters except $, ` (backquote), and \ (Backslash).

Mix Quoting

# WRONG
#echo 'Here's my test...'

# RIGHT
echo 'Here'\''s my test...'

# ALTERNATIVE: It's also possible to mix-and-match quotes for readability:
echo "Here's my test"

Favorite site

References


  1. Wiki.bash-hackers.org-Quotes_and_escaping.pdf ↩