Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to safely print the variable content with spaces.
Bash Scripting
echo [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the variable causes word splitting.
Using single quotes prevents variable expansion.
✗ Incorrect
Using double quotes around the variable ensures spaces are preserved and prevents word splitting.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting causes syntax errors or splits the value.
Using unquoted spaces breaks the command.
✗ Incorrect
Double quotes allow the string with spaces to be assigned as one value.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted * splits filenames with spaces.
Single quotes prevent globbing.
✗ Incorrect
Using double quotes around * prevents word splitting and preserves filenames with spaces.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the variable causes errors with spaces.
Using single quotes prevents variable expansion.
✗ Incorrect
Double quotes around the variable prevent word splitting and preserve spaces in the filename.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Double quotes around the string preserve spaces; file name is simple; variable expansion is quoted in echo.