Environment variables are a set of values that can affect the way running processes will behave. It is stored in the shell's environment space. This space can be used by any program invoked by the shell, and thus contains a lot of program configuration. Linux (and FreeBSD/Solaris/UNIX) process use environment variable for different purposes. Running programs can access the values of environment variables for configuration purposes. Examples of environment variables include:
- PATH : Search for executable files
- SHELL : Your current shell
You can display values of these environment variables with echo command:
$ echo $PATH $ echo $HOME
Setting (changing) an environment variable on Linux/FreeBSD
Setting an environment variable differs from shell to shell. Setting an environment variable for csh/tcsh shell on Linux/FreeBSD:
Syntax:
setenv variable value
For example, to set or modify the PAGER environment variable under csh or tcsh you need to type command:
$ setenv PAGER less
Setting an environment variable for sh/bash or ksh shell
Syntax:
export variable=value
For example, to set or modify the EDITOR environment variable under sh or bash shell you need to type command:
$ export EDITOR=vim $ export EDITOR=/usr/bin/vim
Shell configuration files
These environment variables defined in shell startup files so that when ever you login next time they are reloaded automatically for you. Under Linux bash is the default shell. Following list summaries bash startup files:
- /etc/profile: The systemwide initialization file, executed when you login into system. Only super-user (root) can make any changes to this file.
- /etc/bash.bashrc (/etc/bashrc): The systemwide per-interactive-shell startup file. Only super-user (root) can make any changes to this file. Generally, bash.bashrc is called from /etc/profile file.
Use above files to setup system wide variables such as JAVA path. Since normal users do not have access to these file they can use following two files:
- /home/user/.bash_profile (~/.bash_profile): The personal initialization file, executed when you log into system.
- /home/user/.bashrc (~/.bashrc): The individual per-interactive-shell startup file
Use text editor such as vi to modify or define new environment variable for you. For example, setup EDITOR variable in your .bash_profile file:
$ vi ~/.bash_profile
OR
$ cd $ vi .bash_profile
Add/modify EDITOR as follows:
$ export EDITOR=/usr/bin/vim
Save file logout and login again or just type following command to load environment changes immediately:
$ ./.bash_profile
See also:
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop











{ 0 comments… add one now }