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: 1452 | 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-01-09][Open System-Linux]
How to send a mail using unix/linux terminal?
[2014-10-17][Open System-Linux]
SETFACL command in Linux to set file access control list
[2014-12-24][Open System-Linux]
XARGS command in Linux with examples
[2015-07-12][Open System-Linux]
EGREP or extended grep in Linux to search patterns
[2014-11-25][Open System-Linux]
DMESG command in Linux : to display or control kernel ring buffer

Total comments: 0
ComForm">
avatar