0
0
Bash Scriptingscripting~10 mins

Double quotes (variable expansion) in Bash Scripting - Interactive Code Practice

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

Complete the code to print the value of the variable name using double quotes.

Bash Scripting
name="Alice"
echo [1]
Drag options to blanks, or click blank then click option'
A'$name'
B"$name"
C$name
D"name"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes prevents the variable from expanding.
Not using quotes can cause issues if the variable contains spaces.
2fill in blank
medium

Complete the code to assign the variable greeting a string that includes the variable name expanded inside double quotes.

Bash Scripting
name="Bob"
greeting=[1]
Drag options to blanks, or click blank then click option'
A"Hello, $name!"
B'Hello, $name!'
CHello, $name!
D"Hello, name!"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes causes the variable name to be printed literally.
Not using quotes can cause syntax errors if the string has spaces.
3fill in blank
hard

Fix the error in the code to correctly print the variable path with spaces using double quotes.

Bash Scripting
path="/home/user/My Documents"
echo [1]
Drag options to blanks, or click blank then click option'
Apath
B'$path'
C$path
D"$path"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the variable causes the path to split into multiple words.
Using single quotes prevents variable expansion.
4fill in blank
hard

Fill both blanks to create a command that prints the variable file with variable expansion and preserves spaces.

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

Fill all three blanks to assign message a string that includes the variable user expanded inside double quotes and an exclamation mark.

Bash Scripting
user="Eve"
message=[1]Hello, [2][3]
Drag options to blanks, or click blank then click option'
A"
B$user
C!"
D'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes prevents variable expansion.
Forgetting to close the double quotes causes errors.