Problem Statement
What is the difference between single quotes, double quotes, and no quotes in bash?
Explanation
Single quotes preserve everything literally - no variable expansion, no command substitution, no escape sequences: echo '$USER \n' outputs literal $USER \n. Only way to include single quote inside single quotes is to end quote, escape quote, start new quote: 'don\'t' or use "don't" with double quotes.
Double quotes allow variable expansion, command substitution, and some escape sequences: echo "$USER \n" expands $USER and interprets \n. Preserve spaces: VAR="value with spaces" keeps spaces. Dollar, backticks, backslash, and double quote can be escaped inside double quotes: echo "\$USER" outputs literal $USER.
No quotes enable word splitting (spaces separate words) and pathname expansion (globbing): FILES=*.txt expands to matching filenames, echo $FILES splits on spaces. Dangerous with variables containing spaces: rm $FILE might delete multiple files if FILE="file 1.txt file 2.txt". Always quote variables: rm "$FILE" treats as single argument.
Best practices: use single quotes for literal strings, double quotes for strings with variables or command substitution, always quote variables in expansions unless you specifically want word splitting. Understanding quoting prevents bugs from unexpected word splitting and ensures proper handling of filenames with spaces and special characters.
