Which command shows environmental variables within the shell?

Study for the SANS560 GIAC Penetration Tester (GPEN) Test. Study with flashcards and multiple choice questions, each question has hints and explanations. Get ready for your exam!

Multiple Choice

Which command shows environmental variables within the shell?

Explanation:
Inspecting the shell's variable state requires understanding the difference between shell variables and environment variables. Environment variables are the ones exported to child processes, while shell variables stay local to the current session. The built-in command set, when run with no arguments, prints every shell variable and function, including those exported to the environment. This provides a complete view of what the shell knows and has defined, which is why it’s the best way to see variables within the shell itself. In contrast, env (and printenv) show only environment variables that would be inherited by child processes, not the full set of shell-local variables. The term getenv isn’t a standard standalone shell command in most shells. So using set gives the most comprehensive snapshot of the shell’s current state.

Inspecting the shell's variable state requires understanding the difference between shell variables and environment variables. Environment variables are the ones exported to child processes, while shell variables stay local to the current session. The built-in command set, when run with no arguments, prints every shell variable and function, including those exported to the environment. This provides a complete view of what the shell knows and has defined, which is why it’s the best way to see variables within the shell itself. In contrast, env (and printenv) show only environment variables that would be inherited by child processes, not the full set of shell-local variables. The term getenv isn’t a standard standalone shell command in most shells. So using set gives the most comprehensive snapshot of the shell’s current state.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy