Skip to content

Linux Environment Variables

Nuno Nogueira edited this page Dec 12, 2022 · 11 revisions

Global Variables

  • To view global environment variables use the env or the printenv command.

Local Variables

  • To view local environment variables use the set command.

User-Defined Variables

  • Set string value without spaces: my_var=Linux

  • Set string value with spaces: my_var="Gnu Linux"

  • Set number value: my_var=7625

  • Unset Variable: unset my_var

User-Defined Variables will only be visible in the shell process being used


Print Variable

  • To print the variable value just use echo $VARIABLE. Example: echo $USER


NOTES:

All global environment variables displayed using the env or printenv commands appear in the set command’s output.

env and printenv produce duplicate listings. However, the env command has additional functionality that printenv does not have, making it the slightly more powerful command.