nerdexam
Linux_Foundation

LFCS · Question #3

Which of the following commands puts the output of the command date into the shell variable mydate?

The correct answer is A. mydate="$(date)". To assign the output of a command to a shell variable, command substitution syntax, typically $(command), is used.

Submitted by brentm· Apr 18, 2026Essential Commands

Question

Which of the following commands puts the output of the command date into the shell variable mydate?

Options

  • Amydate="$(date)"
  • Bmydate="exec date"
  • Cmydate="$((date))"
  • Dmydate="date"
  • Emydate="${date}"

How the community answered

(33 responses)
  • A
    91% (30)
  • C
    3% (1)
  • D
    3% (1)
  • E
    3% (1)

Why each option

To assign the output of a command to a shell variable, command substitution syntax, typically `$(command)`, is used.

Amydate="$(date)"Correct

The `$(date)` syntax performs command substitution, which executes the `date` command and captures its standard output. This output is then assigned as the value to the `mydate` shell variable.

Bmydate="exec date"

`mydate="exec date"` would attempt to replace the current shell with the `date` command, and its output would not be captured into the `mydate` variable.

Cmydate="$((date))"

`mydate="$((date))"` uses arithmetic expansion, which is designed for evaluating mathematical expressions, not for executing commands and capturing their string output.

Dmydate="date"

`mydate="date"` assigns the literal string "date" to the variable `mydate` rather than executing the `date` command and capturing its output.

Emydate="${date}"

`mydate="${{date}}"` is not a valid shell syntax for command substitution or variable assignment.

Concept tested: Shell command substitution

Source: https://www.gnu.org/software/bash/manual/bash.html#Command-Substitution

Topics

#Command substitution#Shell variables#Bash syntax#Linux command line

Community Discussion

No community discussion yet for this question.

Full LFCS Practice