Friday, March 31, 2006

Linux/Unix: Environment variables

What are they ?

Environment variables are a set of dynamic values that can affect the way running processes will behave. All unix like operating systems as well as windows have their set of enviraonment variables. In unix like systems change in environment variable will affect only the child process run by that particular program or shell script which changes the environment.

Examples -

$PATH - shows the directories where shell looks for commands issued by a user
$HOME - shows where user's home directory is located on the file-system

env command shows all environment variables specific to your login.

Setting an environment variable

In bash, following two commands set up an environment variable called 'name'

> name=Ketan
> export name

To verify this, you can

> echo $name
or
> env | grep name

If you want a certain environment variable to be set when you login, keep the two commands in your .bashrc file.

No comments: