Bird
0
0

Which of the following is the correct way to escape a space in a bash filename?

easy📝 Syntax Q12 of 15
Bash Scripting - Quoting and Expansion
Which of the following is the correct way to escape a space in a bash filename?
Amy file.txt
Bmy\ file.txt
Cmy file\.txt
Dmy/file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to escape spaces in bash

    Spaces must be escaped with a backslash to be treated as part of the filename.
  2. Step 2: Check each option

    my\ file.txt uses backslash before space correctly. my file.txt has unescaped space, C escapes dot incorrectly, D uses slash which is a directory separator.
  3. Final Answer:

    my\ file.txt -> Option B
  4. Quick Check:

    Escape space with \ = B [OK]
Quick Trick: Use \ before spaces to keep filename intact [OK]
Common Mistakes:
MISTAKES
  • Not escaping spaces causing command errors
  • Escaping wrong characters like dot instead of space
  • Using slash instead of backslash for spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes