Bird
0
0

Why does the shell expand ~ before running a command, but not inside single quotes like '~'?

hard📝 Conceptual Q10 of 15
Linux CLI - Navigating the File System
Why does the shell expand ~ before running a command, but not inside single quotes like '~'?
ABecause tilde expansion happens only outside quotes
BBecause single quotes escape all expansions
CBecause ~ inside quotes is treated as a normal character
DAll of the above
Step-by-Step Solution
Solution:
  1. Step 1: Understand shell expansions and quoting

    The shell expands ~ to home directory only when unquoted. Single quotes prevent all expansions.
  2. Step 2: Analyze each option

    Because tilde expansion happens only outside quotes is true because tilde expansion is disabled inside quotes. Because single quotes escape all expansions is true because single quotes escape expansions. Because ~ inside quotes is treated as a normal character is true because inside quotes, ~ is literal.
  3. Final Answer:

    All of the above -> Option D
  4. Quick Check:

    Quotes prevent tilde expansion; ~ inside quotes is literal [OK]
Quick Trick: Quotes stop ~ from expanding; use unquoted for shortcuts [OK]
Common Mistakes:
  • Expecting ~ to expand inside quotes
  • Confusing single and double quotes
  • Ignoring shell expansion rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes