Linux:- Environment Variables – Basic

Background

At a basic level, environment variables allow for system customization.

 

Set Environment Variables

Export

To set an environment variable, please use the export command

Syntax


set variable="value"

Sample

set otherUser="labUser"

Read Environment Variables

Export

One can also use the same export command to read environment variables.

Syntax


export

Sample

Scenario:- Read All Environment Variables

Code

export

Output
Image


Scenario:- Read Specific Environment Variable

Code
Syntax

export | grep [variable]

Sample

export | grep 'otherUser'

Output
Image

echo

To display contents we can use the echo command

Syntax


echo

Sample

Display Specific Environment Variable

Outline

To display the contents of a variable, please precede the variable name with the dollar sign.

Code
Sample

echo $otherUser

Output
Image


Use Specific Environment Variable

Outline

To reference the contents of an environment variable, please precede the environment variable with a dollar sign.

Code
Syntax

id $[variable]

Sample

id $otherUser

Output
Image


Summary

Nothing new here!

If you are an MS-Dos User, please compare the Linux commands against the corresponding MS-Dos Commands.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s