nerdexam
CompTIACompTIA

XK0-005 · Question #10151

XK0-005 Question #10151: Real Exam Question with Answer & Explanation

The correct answer is A: printenv | grep $HISTSIZE. To retrieve the value of an environment variable, it must be prefixed with a dollar sign ($) when used with echo or when referenced for filtering printenv output.

System Management

Question

An administrator notices the HISTSIZE variable is 50, using the commands below: HISTSIZE=50 export HISTSIZE The administrator rechecks the HISTSIZE value using echo HISTSIZE but gets no value. Which of the following commands should the administrator use to retrieve its value?

Options

  • Aprintenv | grep $HISTSIZE
  • Becho HISTSIZE
  • Cprintf HISTSIZE
  • Dgrep $HISTSIZE

Explanation

To retrieve the value of an environment variable, it must be prefixed with a dollar sign ($) when used with echo or when referenced for filtering printenv output.

Common mistakes.

  • B. echo HISTSIZE (without the dollar sign) will literally print the string "HISTSIZE", not its value.
  • C. printf HISTSIZE would also literally print the string "HISTSIZE", similar to echo without the dollar sign.
  • D. grep $HISTSIZE by itself would search for the value of HISTSIZE (which is 50 in this scenario) in standard input, not list environment variables.

Concept tested. Retrieving environment variable values

Reference. https://man7.org/linux/man-pages/man1/printenv.1.html

Topics

#Shell variables#Environment variables#Linux commands#Command piping

Community Discussion

No community discussion yet for this question.

Full XK0-005 PracticeBrowse All XK0-005 Questions