Interview Prep/Shell Scripting/Variables, quoting and expansions

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
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Variables, quoting and expansions