Recall & Review
beginner
What is command substitution in bash scripting?
Command substitution lets you run a command and use its output as part of another command or variable assignment.
Click to reveal answer
beginner
How do you use backticks for command substitution?
Place the command inside backticks like this: `command`. Bash runs the command and replaces it with its output.
Click to reveal answer
beginner
What is the modern alternative to backticks for command substitution?
Use $(command) instead of backticks. It is easier to read and can be nested without confusion.
Click to reveal answer
intermediate
Why is $(command) preferred over backticks?
Because it improves readability, allows nesting commands easily, and avoids problems with special characters inside commands.
Click to reveal answer
beginner
Show an example of using command substitution to assign the current date to a variable.
Using backticks: today=`date`
Using $(): today=$(date)
Both store the current date output into the variable today.
Click to reveal answer
Which syntax is correct for command substitution in bash?
✗ Incorrect
Both backticks (`command`) and $(command) are valid ways to do command substitution in bash.
Why might you prefer $(command) over backticks?
✗ Incorrect
$(command) syntax allows nesting commands without confusion, unlike backticks.
What will this command do? today=`date`
✗ Incorrect
The backticks run the date command and assign its output to the variable today.
Which of these is NOT a benefit of using command substitution?
✗ Incorrect
Command substitution does not make commands run faster; it just captures their output.
What happens if you nest backticks like this: `echo `date``?
✗ Incorrect
Nesting backticks is confusing and often causes errors; $(...) syntax is better for nesting.
Explain how to use command substitution in bash and why $(command) is preferred over backticks.
Think about readability and nesting commands.
You got /4 concepts.
Write a bash script snippet that assigns the current date and the current user to variables using command substitution.
Use the modern $() syntax for clarity.
You got /3 concepts.