Book Image

Linux Shell Scripting Essentials

By : Sinny Kumari, Khem Raj
Book Image

Linux Shell Scripting Essentials

By: Sinny Kumari, Khem Raj

Overview of this book

Table of Contents (15 chapters)
Linux Shell Scripting Essentials
About the Author
About the Reviewers

Modifying a shell environment

When a new shell is launched, it has the initial environment set that will be used by any application or command that gets executed in a given shell. We now know that the env or setenv shell builtin command can be used to view which environment variables are set for this shell. The shell also provides the capability to modify the current environment. We can also modify the current bash environment by creating, modifying, or deleting environment variables.

Creating environment variables

To create a new environment variable in a shell, the export shell builtin command is used.

For example, we will create a new environment variable ENV_VAR1:

$ env | grep ENV_VAR1  # Verifying that ENV_VAR1 doesn't exist
$ export ENV_VAR1='New environment variable'

A new environment variable with the name ENV_VAR1 is created. To view a new environment variable, we can call the printenv or env command:

$ env | grep ENV_VAR1
ENV_VAR1=New environment variable
$ printenv ENV_VAR1    #...