Fundamentals 5 min read

Mastering the Linux export Command: A Beginner’s Guide to Environment Variables

This guide explains how the Linux export command works, shows how to list, set, and export variables and functions, and demonstrates configuring persistent environment settings for Bash users.

Open Source Linux
Open Source Linux
Open Source Linux
Mastering the Linux export Command: A Beginner’s Guide to Environment Variables

How to Use the Linux export Command

The export command marks variables that should be passed to child processes, providing a simple yet powerful way for administrators to share environment configuration without restarting the session.

1. Display All Exported Variables

Running export without arguments lists every exported variable and its value. linuxmi@linuxmi:~$ export Use grep to filter the list, for example:

linuxmi@linuxmi:~$ export LINUXMI="Welcome to linuxmi.com"<br/>linuxmi@linuxmi:~$ export | grep -i linuxmi

2. Show Exported Variables of the Current Shell

The -p flag prints the current shell’s exported variables.

linuxmi@linuxmi:~$ export -p

3. Export a Variable

You can assign a value and export it in one step, e.g.: linuxmi@linuxmi:~$ export EDITOR=/usr/bin/gedit Verify with:

linuxmi@linuxmi:~$ export | grep -i EDITOR

4. Export a Function

Use the -f option to export a shell function so that it is available in subshells.

linuxmi@linuxmi:~$ test () { echo "Test Function"; }<br/>linuxmi@linuxmi:~$ export -f test<br/>linuxmi@linuxmi:~$ bash<br/>Test Function

5. Configure Persistent Environment Variables

Append export statements to .bashrc (or another profile file) to make them permanent, for example:

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

After the file is sourced, the new path will be applied on every login.

Summary

The Linux export command is a convenient tool for configuring environment parameters. It is easy to learn, offers a few useful options, and can be used to list, set, and export variables and functions, as well as to make persistent changes to the shell environment.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BashExportEnvironment Variablesshell command
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.