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.
Question
Options
- Aprintenv | grep $HISTSIZE
- Becho HISTSIZE
- Cprintf HISTSIZE
- Dgrep $HISTSIZE
How the community answered
(35 responses)- A71% (25)
- B14% (5)
- C9% (3)
- D6% (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.
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.
echo HISTSIZE (without the dollar sign) will literally print the string "HISTSIZE", not its value.
printf HISTSIZE would also literally print the string "HISTSIZE", similar to echo without the dollar sign.
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
Community Discussion
No community discussion yet for this question.