Bird
0
0

What does the command substitution syntax $(date) do in a bash script?

easy🧠 Conceptual Q11 of 15
Bash Scripting - Quoting and Expansion
What does the command substitution syntax $(date) do in a bash script?
ACreates a new variable named <code>date</code>
BRuns the <code>date</code> command and replaces <code>$(date)</code> with its output
CComments out the <code>date</code> command
DPrints the literal string <code>$(date)</code> without running the command
Step-by-Step Solution
Solution:
  1. Step 1: Understand command substitution

    Command substitution runs the command inside $() and replaces it with the command's output.
  2. Step 2: Apply to $(date)

    The date command outputs the current date and time, so $(date) is replaced by that output.
  3. Final Answer:

    Runs the date command and replaces $(date) with its output -> Option B
  4. Quick Check:

    Command substitution = runs command and inserts output [OK]
Quick Trick: Remember: $() runs command and inserts output [OK]
Common Mistakes:
MISTAKES
  • Thinking it creates a variable
  • Confusing it with comments
  • Expecting literal string output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes