Linux Bash Shell Export Tutorial with Examples – POFTUT

Linux Bash Shell Export Tutorial with Examples


Bash is a shell and a simple programming shell too. There are a lot of variables built-in or externally specified. If a variable is specified externally making this variable system-wide available is a problem. The export command makes variables available system-wide by propagating to the subshells. An exported variable would not be available to the parent processes. This means previously spawned or created process will not get exported variable. Syntax of export is like below there is two way to export some variable.

Directly Export

We can export the newly created variable with the following syntax by using export keyword.

export VAR

In this case, we export all readily defined variables to the subshells.

$ myfw=10.0.0.1
$ export myfw
Directly Export
Directly Export

Export After Defining

We can use the following syntax in order to export all readily defined bash variables.

export VAR=VALUE

In this model, the variable is just defined before exported. After variable definition variable exported to the system-wide.

$ export httpserver=192.168.1.10
Export After Defining
Export After Defining

List Exported Variables

It can be listed exported variables with the -p parameter.

$ export -p
List Exported Variables
List Exported Variables

We can see from the output that there are a lot of exported variables to the bash shell. Some of them are HOME, LANG ,LOGNAME etc.

LEARN MORE  Linux Bash Profile File Configuration with Examples

Leave a Comment