nerdexam
CompTIA

XK0-005 · Question #10151

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…

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

How the community answered

(35 responses)
  • A
    71% (25)
  • B
    14% (5)
  • C
    9% (3)
  • D
    6% (2)

Why each option

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.

Aprintenv | grep $HISTSIZECorrect

The question states `echo HISTSIZE` (without '$') produced no value, which is expected as it would literally echo the string "HISTSIZE". `printenv` lists all environment variables, and piping its output to `grep $HISTSIZE` (which would expand to `grep 50` given the `HISTSIZE=50` and `export HISTSIZE` commands) would effectively filter and show the line where HISTSIZE is defined with its value.

Becho HISTSIZE

echo HISTSIZE (without the dollar sign) will literally print the string "HISTSIZE", not its value.

Cprintf HISTSIZE

printf HISTSIZE would also literally print the string "HISTSIZE", similar to echo without the dollar sign.

Dgrep $HISTSIZE

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

Source: 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 Practice