Operating System - HP-UX
1824294 Members
5067 Online
109669 Solutions
New Discussion юеВ

Difference between export and set command

 
SOLVED
Go to solution
Senthil Prabu.S_1
Trusted Contributor

Difference between export and set command

Hello Gurus,
What is the exact differece between export and set command on any unix machines.....

How about using env?... what diff will this make....Please clarify


Advance Thanks,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: Difference between export and set command

Shalom,

export takes a variable that has been set:

DISPLAY=localhost:0.0

and makes it available to sessions outside your current one.

export DISPLAY=localhost:0.0

Will permit another process, the X server iin this case to operate and work with the display.

The set command merely puts a value in a variable and does not make it available to other processes. Its the same as my DISPLAY statement above without the export command.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Danny Petterson - DK
Trusted Contributor

Re: Difference between export and set command

I think its something like...you could use export under ksh/bash, set or setenv under the likes of csh, etc. Another diff is, that "set" alone shows you the entire environment, export shows you absolutly nothing...
Sandman!
Honored Contributor

Re: Difference between export and set command

The export command is used only for exporting variables to the environment. The set command is a multi-purpose command. It is used for automatically exporting variables as well as to set or clear execution options or perform array operations.

For example "set -a" if used at the start of a script exports all subsequently defined variables. Similarly "set -x" is useful for debugging shell scripts etc. etc. man sh-posix(1) for details.
A. Clay Stephenson
Acclaimed Contributor

Re: Difference between export and set command

What is the exact differece between export and set command on any unix machines.....

I really hate questions of this kind because they are so all inclusive. --- and probably impossible to answer in a finite time.

Difference 1: export has 6 letters; set has 3.
Difference 2: The letters themselves are different.

Moreover ( and more to the point), the question needs a context. For example, "set" and "export" could be database related although I am all but positive your mean in a shell context. Ok, which shell?

If you want exact answers then learn to ask better (if not exact) questions.

Doing a "man sh-posix" or a "man ksh" would be a step in the right direction.
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor
Solution

Re: Difference between export and set command

I'll see if I can guess your real question:

> If I type set, I see a lot of variables. If I assign two variables like this:
>
> ABC=1
> export DEF=2
>
> then set shows both values. So what does export do?

Is that fairly accurate? The answer is that set (with no parameters) shows all local and exported variables. The env command shows *only* exported variables. In the above example, ABC is not exported and does not show up in env and subprocesses will never see it. But DEF is in env and therefore will be seen by any subprocesses.

When you are writing scripts, you need to decide if a variable is needed by another process. Any subprocess that you start will only see the results of the env command.


Bill Hassell, sysadmin
Senthil Prabu.S_1
Trusted Contributor

Re: Difference between export and set command

Hello All,
Thanks a lot for the replies, I would also dig more and post my summary soon.

Coming back to replies,

To Bill Hassell,
Yes, you have answered almost, thanks a lot...

To Clay Stephenson,
I never expected such a harsh reply.... I know this is trivial, but wanted to know more about it, that's why I posted...

I have posted this in sys adm section, so it didnot mean a db question, also I never told so...

I would be happier if there is a option of assigning points in negative...
Also, if you r not interested in questions, for god sake don't reply..... I hope the moderator is watching this thread atleast...
One man's "magic" is another man's engineering. "Supernatural" is a null word.
A. Clay Stephenson
Acclaimed Contributor

Re: Difference between export and set command

I never said your question was trivial or simple; in fact, the exact opposite is what I was trying to point out. Your question, as stated, was so vast and so complex that it was impossible (or all but so) to answer. You will get far better and more meaningful answers if you narrow the scope of your questions. That also will have the effect of indicating that you have done some work on your own.

For example, if you had inquired as to the difference between set and export under the POSIX shell under HP-UX, that would have been a sufficiently narrowly confined question to answer in a reasonable amount of time.

In many areas of science (and computers), it's at least as important to know how to ask questions (of others or of Nature) as it is to know how to answer them. Take a hard look at your original question and I think you will understand the point I was trying to make and I consider that far more important than the answer --- which as I pointed out the man pages will provide.
If it ain't broke, I can fix that.
Senthil Prabu.S_1
Trusted Contributor

Re: Difference between export and set command

I never dump the questions over without even looking at man page or without doing any ground work....

I was able to get some valid points b4 posting here, but wanting to get different options here, so I would help me and everyone, this is what I think forums means....

I really don't you to declare that I have not referred man pages or without ground work, just posting questions here.....Simply rubbish....
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Senthil Prabu.S_1
Trusted Contributor

Re: Difference between export and set command

No more posts received in last one month, so closing it:-)
One man's "magic" is another man's engineering. "Supernatural" is a null word.