Saturday, January 23, 2021
Home A-Z Commands How to Use the Linux Export Command in Everyday Computing

How to Use the Linux Export Command in Everyday Computing

The Linux export command marks which values need to be passed to a set of child processes. It is a simple but useful feature provided by the bash shell. It allows admins to pass configuration parameters for the environment without disrupting the current session. This is why the exported variables are not used until the terminal session has been restarted. Luckily, the export command is very simple to use and easy to master. In this guide, we will advise starting users on how to use export in Linux.

How to Utilize the Linux Export Command

You can make use of export in numerous ways. One common example of this is the use of export for setting up the user environment. Users can simply specify the variables using export and add them to their .profile file. Thus, the environment will be configured that way each time they log in.

1. Display all Exported Variables

When used without any argument, the export command displays a list of all of the exported variables for your environment. You should be able to view the variable’s names and their corresponding values.

$ export

It’s easy to find out information on specific variables by using the Linux grep command alongside export. The below commands illustrates this using a simple example.

$ export TEST="for testing purposes"
$ export | grep -i test

linux export command

2. Display Exported Variables for Current Shell

The -p flag of export prints out a list of all the exported variables for the current Linux shell. Check out the below example to see what do we mean by this.

$ export -p

You can use this command to troubleshoot various configuration issues for the running shell session.

3. Export Variables in Linux

The export command makes it easy to share variables across environments. You can set the value of the variable using an export statement. The below example demonstrates this.

$ export EDITOR=/usr/bin/gedit

This will set the path of gedit as the value of the EDITOR variable. You can confirm this by using grep.

$ export | grep -i EDITOR

4. Export Functions in Linux

Developers can use the -f option export for exporting functions. The following example demonstrates this using simple test functions. You can use this method for writing custom shell scripts.

$ test () { echo "Test Function"; }
$ export -f test
$ bash
$ test

This should display the string “Test Function” in your terminal window. The bash call was used to fork a child process for a bash. Without this, the test function would not print the text.

exporting function in bash shell

5. Configure Environment Properties

You can use the export command in Linux to configure various environmental parameters. For example, if you add the below line to your .bashrc file, it will set it as the path for Snap each time the system reboots.

$ echo export PATH="/snap/bin/lxd:$PATH" >> .bashrc

Do not worry if you’re not familiar with how this works from inside profile files. Simply add the custom exports at the end of the file. This way, you can always find and remove them if you want to.

Ending Thoughts

The Linux export command is a useful tool for configuring environment parameters. Moreover, it is very easy to master since there are only a few different options for this command. We have outlined some examples to help you better understand this tool. Hopefully, you can start to use export for customizing your environment from now on. Let us know your thoughts regarding this guide. Feel free to ask questions regarding export or any other Linux terminal commands below in the comment section.


Please enter your comment!
Please enter your name here

Latest Post

How to Install and Configure Gogs Git Service on Ubuntu Linux

The Gogs is a compact and self-hosted hassle-free Git service that you can install on your Ubuntu Linux server...

The 10 Best GNOME Based Linux Distributions To Check Out in 2021

If you have ever used Linux, then there is no chance that you didn’t hear about GNOME. GNOME is...

How to Install and Use GCC Compiler on Linux System

While building the Linux kernel, the developers had to build a free and open-source compiler to create the kernel...

How to Install and Configure Squid Proxy on Linux System

Squid proxy server is an open-source proxy server for Linux distributions. You can install the Squid proxy server on...

Most Talked Post

Most Stable Linux Distros: 5 versions of Linux We Recommend

At the very beginning, I would like to mention why the term ‘Stable’ comes about Linux OS or distro...

Linux or Windows: 25 Things You Must Know While Choosing The Best Platform

Choosing the best platform - Linux or Windows is complicated. Because both the system is versatile and capable of...

Linux Mint vs Ubuntu: 15 Facts To Know Before Choosing The Best One

Ubuntu and Linux Mint are two popular Linux distros available in the Linux community. Ubuntu is a derivative of...

Best Things To Do After Installing Linux Mint 20 “Ulyana”

Linux Mint is one of the best Linux distros for newcomers, especially those who come from other Operating Systems...