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:
Step 1: Identify how to escape spaces in bash
Spaces must be escaped with a backslash to be treated as part of the filename.
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.
Final Answer:
my\ file.txt -> Option B
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
Master "Quoting and Expansion" in Bash Scripting
9 interactive learning modes - each teaches the same concept differently