Monday, 26 August 2019

Environment variables in Linux

Environment variables

Environment variable is a storage location where is name and value. They often affect the way programs behave.

 printenv command – Print all or part of environment.
env command – Print all exported environment or run a program in a modified environment.
set command – Print the name and value of each shell variable.
printenv without arguments print all variables.
printenv name_of_variable - print only this variable
example:
 [root@rifle ~]# printenv HISTSIZE
1000
  The same result you can get using the echo command. The variable name has to be used with $ .
[root@rifle ~]# echo $HISTSIZE
1000
!Some information about used variables can be found in man pages of the command.
! Environment variables names are case sensitive.

Creating/change variables

export VAR='value'
export EDITOR='vi'

Removing variables

unset  var

Preserve variables from session to session

Save them to your personal ~/.bash_profile file

No comments: