0
0
Bash Scriptingscripting~10 mins

Why quoting rules prevent errors in Bash Scripting - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to safely print the variable content with spaces.

Bash Scripting
echo [1]
Drag options to blanks, or click blank then click option'
A$"var"
B$var
C'$var'
D"$var"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the variable causes word splitting.
Using single quotes prevents variable expansion.
2fill in blank
medium

Complete the code to assign a string with spaces to a variable correctly.

Bash Scripting
name=[1]
Drag options to blanks, or click blank then click option'
AJohn_Doe
B"John Doe"
C'John Doe'
DJohn Doe
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting causes syntax errors or splits the value.
Using unquoted spaces breaks the command.
3fill in blank
hard

Fix the error in the command to safely list files with spaces in their names.

Bash Scripting
for file in [1]; do echo "$file"; done
Drag options to blanks, or click blank then click option'
A"*"
B*
C'*'
D\*
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted * splits filenames with spaces.
Single quotes prevent globbing.
4fill in blank
hard

Fill both blanks to safely read a filename and print its content.

Bash Scripting
read -r filename
cat [1]$filename[2]
Drag options to blanks, or click blank then click option'
A"
B'
D\
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the variable causes errors with spaces.
Using single quotes prevents variable expansion.
5fill in blank
hard

Fill all three blanks to safely append a string with spaces to a file.

Bash Scripting
text=[1]
file=[2]
echo [3] >> "$file"
Drag options to blanks, or click blank then click option'
A"Hello World"
Boutput.txt
C$text
Doutput txt
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting strings with spaces causes errors.
Using unquoted variables in echo can split words.
File names with spaces need quotes.