Thursday, September 16, 2010

Environment Variables In Linux

Environment variables handle or control the flow of running processes in the operating system. Environment variable has a value and a variable which is using some particular application. As a example in Java program, Operating system consist a variable call "PATH" and the value is the path of java's bin directory. Likewise most of the programs (actually running processes) are using Environment Variables for their various types of activities.

We can easily view already stored Environment Variables using Terminal.

  • Display Currently defined variable list.
printenv 
  • Display Currently defined variable list.
echo $PATH (display the program search path)
  • using env
You can run a command in a modified version of the current environment (see man page) also it is using to display whole environment variables list. Just typeenv also It can use for delete or add a variable temporally.

  • Set Environment variables.
Ex. Set Java bin PATH
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

  • Erasing Environment Variables.
You can do it easily giving null value
export PATH=
Using above commands you can handle environment variables temporally. If you want to handle Environment Variables Permanently you want to know how they are stored in your architecture.

Environment Variables are stored in two difference ways called Session Specific and System Specific.

1. Session Specific Variables.
These are mostly stored in the specific hidden files/scripts in your home directory. Specially we can identify 3 ways to store Environment Variables.

  • ~/.profile
  • ~/.bash_profile or ~/.bash_login
  • ~/.bashrc
  • ~/.bash_logout
2. System Specific Variables
These Variables are using whole System and affected all users/sessions in runing time.

  • /etc/profile
  • /etc/bash.bashrc
  • /etc/environment

No comments:

Post a Comment