Bird
0
0

Which of the following is a correct way to assign the output of the command date to a variable named today?

easy🧠 Conceptual Q2 of 15
Bash Scripting - Quoting and Expansion
Which of the following is a correct way to assign the output of the command date to a variable named today?
ABoth A and C
Btoday=date
Ctoday=$(date)
Dtoday=`date`
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for command substitution

    Both backticks (`date`) and $() syntax ($(date)) correctly capture command output.
  2. Step 2: Verify variable assignment

    Assigning the output to a variable uses the syntax: variable=`command` or variable=$(command).
  3. Final Answer:

    Both A and C -> Option A
  4. Quick Check:

    Variable assignment with backticks or $() = Both A and C [OK]
Quick Trick: Use either backticks or $() for command substitution [OK]
Common Mistakes:
MISTAKES
  • Assigning command name instead of output
  • Missing backticks or $() around command
  • Using wrong syntax like today=date

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes