Operating System - HP-UX
1833772 Members
2284 Online
110063 Solutions
New Discussion

why do you export a variable ?

 
SOLVED
Go to solution
Indrajit Bhagat
Regular Advisor

why do you export a variable ?

why do you export a variable ?
thanks to all of those who spend few time to reply my answer.
8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: why do you export a variable ?

So it can be used.

Sunny Jaisinghani
Trusted Contributor
Solution

Re: why do you export a variable ?

so that u can use that variable again and again without resetting the value to that variable.
Guna_2
Regular Advisor

Re: why do you export a variable ?

Hi

I think after export a variable it will become as a environmental veriable. So ur child process also will inherits this variable.


Rgds,
Guna
Yogeeraj_1
Honored Contributor

Re: why do you export a variable ?

hi Indrajit!

export is a command that sets environment variables for use for the entire duration of the session, unless changed. export is usually a shell built-in command.

For example, if you have 3 scripts to run simultaneously at the command line and all the 3 scripts need the same environment variables. You can just export the variables prior to the execution of script and just use it in the three scripts. This way your script becomes simpler too!

hope this helps!

Kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Victor Fridyev
Honored Contributor

Re: why do you export a variable ?

If in a shell you define
varname=value
the varname is accessible in the shell only (local variable).

If you define it as
export varname=value,

the variable is accessible for the shell children as well.

HTH
Entities are not to be multiplied beyond necessity - RTFM
Rob Beaumont
New Member

Re: why do you export a variable ?

Indrajit,

The reason is related to 'scope' of the variable. As analogy, it can be compared (loosely though) with scope of a variable in programming language. To summerize, the 'scope' of the variable is limited to the shell (as rightly informed) and when exported the 'scope' extends upto the session.

Regards
Indrajit Bhagat
Regular Advisor

Re: why do you export a variable ?

thank to all of you
Bill Hassell
Honored Contributor

Re: why do you export a variable ?

As mentioned, export makes a variable useable to other processes. In your shell, each command you type such as vi or date or bdf will first create a copy of your current exportable environment and the the process runs in this environment. If you simply assign a variable but not export it, no other process started from your shell can see the variable. You can see the difference with these two commands:

set
env

The first shows your shell's total variable list but env shows only the exported variables.


Bill Hassell, sysadmin