Home » 2014 » September » 20 » Export command in Linux

9:53 AM
Export command in Linux

Share on Google+

EXPORT is one of the most useful command in linux. It is used to set global variables in linux environment


export [-fn] [name[=word]] ...
export -p

              Names supplied to export are marked for automatic export to the environment of 

subsequently  executed  commands.

If  the  -f  option  is given, the names refer to functions. 

[shanky@HYDBMW ~]$ export -f
module ()
    eval `/usr/bin/modulecmd bash $*`
declare -fx module


If no names are given, or if the -p option is supplied, a list of all names that are exported in this shell is printed. 

declare -x MAIL="/var/spool/mail/shanky"
declare -x MODULEPATH="/usr/share/Modules/modulefiles:/etc/modulefiles"
declare -x MODULESHOME="/usr/share/Modules"
declare -x OLDPWD
declare -x PATH="/usr/lib64/qt-


declare -x PWD="/home/shanky"
declare -x QTDIR="/usr/lib64/qt-3.3"
declare -x QTINC="/usr/lib64/qt-3.3/include"
declare -x QTLIB="/usr/lib64/qt-3.3/lib"


The -n option causes the  export property  to be removed from each name. 

[shanky@HYDBMW ~]$ export -n shanky 

the "shanky" will be removed from export list

If a variable name is followed by =word, the value of the variable is set to word

To set/export a global variable, we can use following two ways:

export var=value

shanky@localhost:> export NAME=SHANKAR
shanky@localhost:> echo $NAME

shanky@localhost:> export -p

declare -x NAME="SHANKAR"



export $var;

[shanky@HYDBMW ~]$ var=shanky
[shanky@HYDBMW ~]$ export $var
[shanky@HYDBMW ~]$ echo $var


EXPORT returns an exit status of 0 unless an invalid option is  encountered,  one  of  the      names is not a valid shell variable name, or -f is supplied with a name that is not a function.

shanky@localhost:> export -f aaaaa
-bash: export: aaaaa: not a function
shanky@localhost:> echo $?

Its always suggsted to add all your exports into your profile file to make it persistent for your profile.

[shanky@HYDBMW ~]$ cat .bash_profile
# User specific environment and startup programs


export PATH


Category: Open System-Linux | Views: 1311 | Added by: shanky | Tags: how to export global variables, set global variables in linux, export command in unix, shanky's portal | Rating: 0.0/0

Related blogs

You may also like to see:

[2014-12-05][Open System-Linux]
PIDSTAT command for debugging and analysis of Performance of Linux process
[2014-01-08][Open System-Linux]
SSH Login Setup
[2017-08-13][Open System-Linux]
Perl trick to remove Ctrl - M charater from a file
[2014-12-16][Open System-Linux]
CUT command in Linux : cut the file vertically
[2015-06-08][Open System-Linux]
CHAGE command in LINUX

Total comments: 0