Linux Foundation Certified System Administrator (LFCS) — Question 128
Which of the following commands puts the output of the command date into the shell variable mydate?
Answer options
- A. mydate="$(date)"
- B. mydate="exec date"
- C. mydate="$((date))"
- D. mydate="date"
- E. mydate="${date}"
Correct answer: A
Explanation
The correct answer is A, as it correctly captures the output of the date command using command substitution. Option B incorrectly uses exec, which does not assign output to a variable. Option C attempts to use arithmetic expansion, which is not applicable here, while D and E simply assign the command name or an uninitialized variable, respectively, without capturing the command's output.