Mastering the export Command: How to View and Set Environment Variables in Linux
This guide explains the Linux export command, detailing its purpose for converting shell variables and functions into environment variables, the syntax, available options such as -f, -n, -p, and provides practical examples for listing, setting, and removing environment variables.
export: Display or Set Environment Variables
Function Description
export command is used to export shell variables as environment variables, or export shell functions as environment variables.
When a variable is created, it is not automatically known to subsequently created shell processes. The export command can pass variable values to subsequent shells. When a shell script is invoked, it does not automatically inherit variables defined in the caller unless those variables have been explicitly exported. export can be used to pass one or more variable values to any subsequent script.
Command Syntax
export [options [arguments]]Option Meanings
-f : indicates that the name in the variable list is a function name
-n : delete the specified environment variable
-p : list all environment variables assigned by the shell
Argument Meaning
Variable: specifies the environment variable to export or delete.
Reference Examples
(1) List all environment variables
[root@cnLinuxer ~]# export -p
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE="1000"
declare -x HOME="/root"
declare -x HOSTNAME="cnLinuxer"
declare -x LANG="zh_CN.UTF-8"
declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"
declare -x LOGNAME="root"
... (output truncated)(2) Set the value of environment variable HISTSIZE to 1500 [root@cnLinuxer ~]# export HISTSIZE=1500 (3) Add environment variable (JAVA) to ~/.bashrc
PATH=/usr/local/jdk1.7.0/bin:$PATHSigned-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.
