Bash scripting – Understanding Linux Environment variables - PowerPoint PPT Presentation

About This Presentation
Title:

Bash scripting – Understanding Linux Environment variables

Description:

Bash scripting – Understanding Linux Environment variables – PowerPoint PPT presentation

Number of Views:108

less

Transcript and Presenter's Notes

Title: Bash scripting – Understanding Linux Environment variables


1
Bash scripting Understanding Linux Environment
variables
Posted by Prince DAN January 13, 2020 in DevOps
Linux Environment variables are variables that
store the information for the shell environment
the shell sessions. These variables are accessed
by any scripts or Linux program to get a
frequently accessed value. We have discussed
briefly Linux Environment variables, but what
exactly is a variable. Most of you might know,
but for those who dont, a variable is used for
storing some information like a string or a
number or file location. When a variable is
referenced in a program or shell script,
basically it is requesting the stored value for
those variables. Variables allow us to store some
frequently accessed data so that we dont have
to write it again and again. Recommended Read
Important PostgreSQL commands that every beginner
should know Also Read Bash Scripting-2- Using
VARIABLES in Linux shell scripts
2
  • Now back to the Linux Environment variable, as
    mentioned above we also reference them as
    environment variables. These can be of two
    types-
  • Local Variables These variables are created for
    a single shell session are only available
    until a session is running. Once a session ends,
    we cant use them again, these variables are
    only available for the terminal where they were
    set cant be used on other terminals.
  • Global variables These are system-wide Linux
    Environment variables are available to be used
    for all shells, terminals sessions.

Important Linux Environment variables commands
  • Create a local Linux environment variable
  • To create a local variable, use the following
    command,
  • new_varaiable_nametest value
  • Use this without any spaces.
  • Create an global Linux environment variable
  • To create a global environment variable, first,
    create a local variable then export it,
  • new_varaiable_nametest value export
    new_varaiable_name
  • To check the list of all Linux Environment
    variables, use the following command, set
  • To get value of only a single variable,
    printenv variable_name
  • Unset an environment variable
  • To remove a variable from the list of environment
    variables, we can run the following command,

3
PATH command is another important command that we
might use, it is basically used to save path for
either a program or script. We can set the path a
script next time when we need to execute the
script, we need not use the full path can only
run the script directly, To set the path, use
PATHPATH/home/test-user/testing.sh Now to run
the script, only have to run testing.sh the
script will run, irrespective of whichever
directory we are in. We can also set the path for
a directory that might contain the scripts
this will also work the same way,
PATHPATH/home/test-user Thats it for our
tutorial on Linux Environment Variables. Please
feel free to send in any questions or queries
using the comment box below.
If you think we have helped you or just want to
support us, please consider these- Connect to
us Facebook T witter Linkedin TheLinuxGURUS
are thankful for your continued support.
TheLinuxGURUS.com
Write a Comment
User Comments (0)
About PowerShow.com