What is the difference between single quotes, double quotes and `$'...'`?
BeginnerConceptVariables, quoting and expansions
Answer
- Single quotes: everything literal, no expansion, cannot contain a single quote.
- Double quotes: one word, but
$var,$(cmd),$((expr)), backticks, and backslash escapes of$,",\and the backtick still work. $'...'(ANSI-C quoting): interprets escapes such as\n,\t,\x1b,\'.
name=prod
echo 'env=$name' # env=$name
echo "env=$name" # env=prod
IFS=$'\n' # a real newline character
echo $'it\'s ready' # it's ready
More on Variables, quoting and expansions
What are the rules for assigning variables in Bash?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerExplain the difference between `"$@"`, `"$*"`, `$@` and `$*`.IntermediateWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?IntermediateHow do you do search-and-replace, substrings, length and case conversion without external tools?Intermediate