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.
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 linuxmi2. Show Exported Variables of the Current Shell
The -p flag prints the current shell’s exported variables.
linuxmi@linuxmi:~$ export -p3. 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 EDITOR4. 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 Function5. 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" >> .bashrcAfter 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
