Shell Scripting – Mnemonic for Shell Double vs. Single Quotes

quotingscriptingshell

I don't do enough scripting to remember, without looking up, whether double or single quotes result in a Unix variable being substituted.

I definitely understand what is going on. My question is does anyone have a memory trick for making the correct quoting rule stick in my head?

Best Answer

Single quotes are simple quotes, with a single standard: every character is literal.
Double quotes have a double standard: some characters are literal, others are still interpreted unless there's a backslash before them.

Single quotes work alone: backslash inside single quotes is not special.
Double quotes pair up with backslash: backslash inside double quotes makes the next character non-special.