Recall & Review
beginner
What happens to variables inside double quotes in bash scripting?
Variables inside double quotes are expanded to their values. This means the shell replaces the variable name with its content.
Click to reveal answer
beginner
Compare single quotes and double quotes in bash regarding variable expansion.
Single quotes prevent variable expansion; everything inside is treated literally. Double quotes allow variable expansion, so variables inside are replaced by their values.
Click to reveal answer
intermediate
Why use double quotes around variables in bash scripts?
Double quotes protect the variable's value from word splitting and globbing, while still allowing the variable to expand. This helps avoid errors with spaces or special characters.
Click to reveal answer
beginner
Example: What is the output of this script?<br>
name="Alice" echo "Hello, $name!"
The output will be: Hello, Alice!<br>The variable $name is expanded inside the double quotes.
Click to reveal answer
beginner
What happens if you use double quotes but forget the $ sign before a variable?
The variable name is treated as a normal string, not expanded. For example, "Hello, name" prints exactly 'Hello, name' instead of the variable's value.
Click to reveal answer
What does double quotes do to variables in bash?
✗ Incorrect
Double quotes allow variables to be expanded to their values in bash.
Which quotes prevent variable expansion in bash?
✗ Incorrect
Single quotes treat everything literally, so variables inside are not expanded.
Why should you put variables inside double quotes when using them?
✗ Incorrect
Double quotes allow variable expansion and protect from word splitting and globbing.
What will this command print?<br>name="Bob"<br>echo "Hi $name!"
✗ Incorrect
The variable $name is expanded inside double quotes, so it prints 'Hi Bob!'.
What happens if you write echo "Hello, name" without $?
✗ Incorrect
Without $, 'name' is treated as a normal string and printed literally.
Explain how double quotes affect variable expansion in bash scripting.
Think about how the shell treats variables inside different quotes.
You got /3 concepts.
Describe a situation where forgetting to use double quotes around a variable could cause a problem.
Imagine a variable with spaces used without quotes.
You got /4 concepts.