0
0
Bash Scriptingscripting~20 mins

Escape characters (\) in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Escape Character Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this Bash command?
Consider the following command in a Bash shell:

echo "Hello\nWorld"

What will this command output?
Bash Scripting
echo "Hello\nWorld"
AHello\nWorld
B
Hello
World
CHello World
DHello\ World
Attempts:
2 left
💡 Hint
Remember that double quotes allow some escape sequences, but \n is not interpreted by echo by default.
💻 Command Output
intermediate
1:30remaining
What does this command print?
What is the output of this Bash command?

echo -e "Hello\nWorld"
Bash Scripting
echo -e "Hello\nWorld"
AHello\nWorld
B
Hello
World
CHello\ World
DHello World
Attempts:
2 left
💡 Hint
The -e option enables interpretation of backslash escapes.
📝 Syntax
advanced
2:00remaining
Which command correctly prints a backslash character?
You want to print a single backslash character (\) in Bash using echo. Which command will do this correctly?
Aecho "\\"
Becho '\\'
Cecho "\"
Decho \
Attempts:
2 left
💡 Hint
Backslash is an escape character, so you need to escape it to print it literally.
🔧 Debug
advanced
2:00remaining
Why does this command fail to print a newline?
This command is intended to print two lines:

echo "Line1\nLine2"

But it prints the literal string instead. Why?
Bash Scripting
echo "Line1\nLine2"
ABecause double quotes prevent escape sequences
BBecause echo requires single quotes to interpret \n
CBecause \n is not a valid escape sequence in Bash
DBecause echo does not interpret \n without -e option
Attempts:
2 left
💡 Hint
Try adding an option to echo to enable escape sequences.
🚀 Application
expert
2:30remaining
How to assign a variable with a literal backslash in Bash?
You want to assign a variable named path with the value C:\Users\Admin (including backslashes) in Bash. Which assignment is correct?
Apath="C:\Users\Admin"
Bpath="C:\\Users\\Admin"
Cpath='C:\\Users\\Admin'
Dpath=C:\Users\Admin
Attempts:
2 left
💡 Hint
Single quotes prevent escape sequence interpretation in Bash.