How To Set, Get and Change Bash Environment Variable? – POFTUT

How To Set, Get and Change Bash Environment Variable?


Bash shell is used for a lot of things in Linux systems. Most of the applications run with bash. Bash is a shell but provides an environment that can be used to programming. Variables are core of the programming. Bash provides variables too. There are default variables as well as user defined variables.

Get Existing Bash Environment Variables

Bash provides a lot of variables by default. Those variables can be used to get information about shell, system, running applications etc. We can list all ready created environment variables with the env command like below.

$ env
Get Existing Bash Environment Variables
Get Existing Bash Environment Variables

Create and Set Variable

Creating and setting a variable in bash is very easy. We just need to specify the variable name and set the value with equal sign like below. In this example we will create a variable named count and set its value integer 0.

$ count=0

Get Variable

Getting a variable values is very easy we just need to add $ to the start of the variable name. In this example we will print the count variable value.

$ echo $count 
0

Change Variable Value

We can change all ready created variables value. It is the same way of creating a variables. So we will just provide the variable name the the value. In this example we will set variable count to the 1.

$ count=1 
$ echo $count 
1

 

How To Set, Get and Change Bash Environment Variable? Infografic

How To Set, Get and Change Bash Environment Variable? Infografic
How To Set, Get and Change Bash Environment Variable? Infografic

 

LEARN MORE  How To Check If File Exists In Linux Bash?

1 thought on “How To Set, Get and Change Bash Environment Variable?”

Leave a Comment