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

FORMAT

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-

3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:

/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/shanky/bin"
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
SHANKAR

shanky@localhost:> export -p

declare -x NAME="SHANKAR"

or

var=value;

export $var;

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

 

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 $?
1


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

PATH=$PATH:$HOME/bin

export PATH

 
 

Category: Open System-Linux | Views: 1348 | 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-03][Open System-Linux]
GREP command in Linux to search for a pattern
[2014-10-06][Open System-Linux]
Time command in Linux to give resource usage
[2015-04-23][Open System-Linux]
15 Great DATE command examples
[2014-03-25][Open System-Linux]
Create a new user in Linux system: useradd
[2015-06-08][Open System-Linux]
CHAGE command in LINUX

Total comments: 0
ComForm">
avatar