Shell Variables

Shell have variables like variables used in other programming languages. Some shell variables are HOME( our login directory), PATH(list of directories to search for commands). Strings such as $1 are called positional parameters. Except positional parameters, shell variables can be accessed, modified and created.

We can modify PATH as

PATH=:/bin;/usr/bin

There should not be any space around ‘=’ sign.

We can list the shell variables and its value currently in our system using set command. We can also display individual values using a ‘$’ symbol.

eg: echo $PATH

When we are creating or modifying the value of a shell variable, the value is only associated with that shell. It cannot be used in any of the sub-shells.

To use the value of a shell variable in sub-shells- we have to use the ‘export’ command.

x=hai

export x

Now the value of x in the sub-shells is also ‘hai’.

Advertisements

About Odol Shinu

I've completed my B Tech in Information Technology in 2010 from Government Engineering College Sreekrishnapuram Palakkad under Calicut University.

Posted on August 17, 2010, in GNU/Linux. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: