Linux environment variables

From Logic Wiki
Jump to: navigation, search


Commands

  • env – The command allows you to run another program in a custom environment without modifying the current one. When used without an argument it will print a list of the current environment variables.
  • printenv – The command prints all or the specified environment variables.
  • set – The command sets or unsets shell variables. When used without an argument it will print a list of all variables including environment and shell variables, and shell functions.
  • unset – The command deletes shell and environment variables.
  • export – The command sets environment variables.


Variables have the following format

KEY=value
KEY="Some other value"
KEY=value1:value2

SETTING

EXPORT KET=VALUE

/etc/environment - Use this file to set up system-wide environment variables. Variables in this file are set in the following format:

FOO=bar
VAR_TEST="Test Var"

/etc/profile - Variables set in this file are loaded whenever a bash login shell is entered. When declaring environment variables in this file you need to use the export command:

export JAVA_HOME="/path/to/java/home"
export PATH=$PATH:$JAVA_HOME/bin