Master the Linux export Command: Beginner’s Guide to Environment Variables
This article explains how to use the Linux export command to set and view environment variables, demonstrates common options such as listing all exports, exporting specific variables, exporting functions, and shows how to persist settings in shell configuration files, providing practical examples for beginners.
The export command in Bash marks variables so that they are passed to child processes, allowing administrators to configure environment parameters without restarting the session.
Displaying All Exported Variables
Running export without arguments lists every exported variable and its value.
linuxmi@linuxmi:~$ exportFinding a Specific Variable
You can pipe the output to grep to locate a particular variable.
linuxmi@linuxmi:~$ export LINUXMI="Welcome to linuxmi.com"
linuxmi@linuxmi:~$ export | grep -i linuxmiDisplaying Current Shell Exported Variables
The -p flag prints the list of exported variables in a reusable format.
linuxmi@linuxmi:~$ export -pExporting a New Variable
Assign a value and export it in one step, then verify with grep.
linuxmi@linuxmi:~$ export EDITOR=/usr/bin/gedit
linuxmi@linuxmi:~$ export | grep -i EDITORExporting a Function
Use the -f option to export a shell function, making it available to subshells.
linuxmi@linuxmi:~$ test () { echo "Test Function"; }
linuxmi@linuxmi:~$ export -f test
linuxmi@linuxmi:~$ bash
Test Function
linuxmi@linuxmi:~$ test
Test FunctionPersisting Variables Across Sessions
Append an export statement to .bashrc (or another profile file) to set the variable each time a new shell starts.
linuxmi@linuxmi:~$ echo export PATH="/snap/bin/lxd:$PATH" >> .bashrcAfter editing, the new PATH will be applied on the next login or when the profile is sourced.
Conclusion
The export command is a simple yet powerful tool for configuring environment parameters in Linux. By mastering its basic options—listing variables, exporting specific values, exporting functions, and persisting settings—you can efficiently manage your 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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
