Bird
0
0

You want to assign the output of the command date +%Y to a variable year. Which is the correct way to do this in bash?

hard🚀 Application Q8 of 15
Bash Scripting - Variables
You want to assign the output of the command date +%Y to a variable year. Which is the correct way to do this in bash?
Ayear=$(date +%Y)
Byear = $(date +%Y)
Cyear= $(date +%Y)
Dyear= '$(date +%Y)'
Step-by-Step Solution
Solution:
  1. Step 1: Understand command substitution syntax

    Use $(command) to assign command output to a variable.
  2. Step 2: Check for spaces around =

    Variable assignment must have no spaces around =.
  3. Final Answer:

    year=$(date +%Y) -> Option A
  4. Quick Check:

    Command substitution with no spaces = year=$(date +%Y) [OK]
Quick Trick: No spaces around = and use $(command) for output assignment [OK]
Common Mistakes:
MISTAKES
  • Spaces around =
  • Using quotes incorrectly
  • Missing $ in command substitution

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes