LPIC-1 Exam 102 v5 (Linux Administrator) — Question 103
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: D
Explanation
The correct answer is D, as using $(date) executes the date command and captures its output into the mydate variable. Option A assigns the literal string 'date' instead of its output, while B incorrectly uses exec, which doesn't capture output. Option C attempts to use arithmetic expansion which is not applicable here, and E references an existing variable rather than executing the command.