QuestionQ183

Essential Commands

The output of the date command should be saved in the variable actdat. Which statement accomplishes this correctly?

  • A actdat=date
  • B set actdat='date'
  • C date | actdat
  • D date > $actdat
  • E actdat=date
Explanation

In shell scripting, backticks (or $(...)) perform command substitution, executing the enclosed command and substituting its output. Therefore actdat=date`` runs the date command and assigns its output (the current date/time string) to the variable actdat. The other options either assign a literal string ('date'), use invalid syntax for variable assignment (set, pipe), or redirect output to a file rather than storing it in a variable.

Community Discussion

No comments yet. Be the first to start the discussion!