How do you display environment variables?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Linux / Shell Scripting topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
printenv prints all environment variables. printenv VARNAME prints a specific variable's value. env also lists all environment variables. echo $VARNAME prints a specific variable (e.g., echo $PATH). set shows all shell variables (including local ones not in the environment). declare -p shows all declared variables with their attributes. To see the environment of a running process: cat /proc/PID/environ | tr '\0' '\n'. Use export -p to see all exported variables in a format that can be re-used in another shell.
Common Mistake
A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.