Which of the following commands puts the output of the command date into the shell variable mydate?
Which of the following commands puts the output of the command date into the shell variable mydate?
A . mydate="$(date)"
B . mydate="exec date"
C . mydate="$((date))"
D . mydate="date"
E . mydate="${date}"
Answer: A
Explanation: ∗∗ ∗∗
(date)" Comprehensive Thecorrectwaytoputtheoutputofthecommanddateintotheshellvariablemy dateistousecommandsubstitutionwiththesyntax(command). This will execute the command in a subshell and replace the expression with its standard output. The double quotes around the expression will prevent word splitting and globbing of the output. The other options are incorrect because they will either assign a literal string to the variable, use an invalid syntax, or try to execute the command as an arithmetic expression.
Reference: [LPI Linux Essentials – Topic 105: Shells, Scripting and Data Management]
[LPI Linux Administrator – Exam 102 Objectives – Topic 105: Shells and Shell Scripting]
Latest 102-500 Dumps Valid Version with 194 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund