Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

difference between set and setenv?

715 views
Skip to first unread message

Jim Harkins

unread,
Jan 18, 1993, 8:53:16 PM1/18/93
to
What exactly is the difference between the set command and setenv? I know
I sometimes want to use one and other times use the other, but I can't quite
put into words which should be used where.

jim

--
Plumbers Motto: A flush beats a full house.
--------------------------------------------------------------
Jim Harkins [ucsd|uunet]!pacdata!jim
Pacific Data Products j...@pacdata.com
--------------------------------------------------------------

John Ellithorpe

unread,
Jan 19, 1993, 11:12:21 AM1/19/93
to
On Tue, 19 Jan 1993 01:53:16 GMT, ji...@pacdata.com (Jim Harkins) said:

> What exactly is the difference between the set command and setenv? I know
> I sometimes want to use one and other times use the other, but I can't quite
> put into words which should be used where.

> jim

I'm assuming you are using csh or some variant, like tcsh. Anyway, the set
command sets a shell variable and setenv sets an environment variable. Your
shell variables are only accessible in the shell which you are currently in.
Environment variables, as you may have guessed, are set throughout your entire
login.

Therefore, you should set shell variables to what you need only in that shell,
and probably should be set in the .cshrc file. Environment variables should
be set in your .login file and should set things like PATH, HOME, etc. Stuff
which you may need in any window you have open.

I hope that a bit clearer.

John

--

===============================================================================
John Ellithorpe | Internet: jd...@maggie.mit.edu
Dept. of Physics, Rm 26-349 | Phone : (617) 253-3074 Office
Massachusetts Institute of Technology | (617) 253-3072 Lab
Cambridge, MA 02139 | (617) 236-4910 Home
===============================================================================

Mike Ales

unread,
Jan 19, 1993, 12:45:32 PM1/19/93
to
One additional comment here for any new-bies, that I
have been asked before.

Any environment variables that are set using setenv
will only be available in shells created
from the shell in which one did the setenv. They will
not be fanned out to any other shells one might already
have floating around when you do a setenv in anyone
of them. Therefore environment variables are not
Global but they are inheritable.

This works as John outlines for all of the "sub-shells"
created from logging in.

Regards, Mike Ales

Daniel Louis Smith

unread,
Jan 19, 1993, 4:08:30 PM1/19/93
to
In <1993Jan19.0...@pacdata.uucp> ji...@pacdata.com (Jim Harkins) writes:

> What exactly is the difference between the set command and setenv? I know
> I sometimes want to use one and other times use the other, but I can't quite
> put into words which should be used where.


Let's look at it from the csh point of view...

"set" is for changing the way that csh behaves, and with few
exceptions (most noteably $path), does not propagate to any child
processes of that shell. Changing csh's $path also changes the
environment variable $PATH.

"setenv" is for affecting your login session from the
current shell on down (in other words, setting an environment variable
in one xterm usually is not going to affect something in another. Things
like $HOME, $USER, $LOGNAME, $SHELL, $PRINTER, $EDITOR, $DISPLAY, and
$EXINIT, can be queried in child processes through the getenv(3) call
(or $ENV{"SOMEVAR"} in perl).

Most Environment variables are set up in a .login file,
and most csh vars are set up in .cshrc, but this isn't a hard and
fast rule, and X11 has done much to muddy the distinction :-)

The direction I'm leaning towards is not having a .login at all.

I was just thinking to myself "why not ditch csh vars entirely,
and work off of environment variables for things such as the prompt and
filec?". I've answered my own question though... shells need to have
their own set of variables for space reasons. You really wouldn't want
25-50 extra environment variables propagating to *each* process that
is launched from a shell...it would eat memory. So... a basic rule of
thumb is: do I want this var to be seen by child processes? If so,
then make it an environmemt variable - this often comes into play in
shell scripts.

I could go off on a tangent about X resources, but I'm hungry
and it's time for lunch :-)

Daniel

--
d...@autodesk.com dans...@well.sf.ca.us
Daniel L Smith, Autodesk, Sausalito, California, (415) 332-2344 x 2580
formerly dans...@autodesk.com, changed my login recently

Wolfgang Sander-Beuermann

unread,
Jan 22, 1993, 5:52:55 AM1/22/93
to
Looking at your question, I'll assume, you work with csh (i.e. you can
see a % as (or within) your prompt); then it is as following:

set ... defines variables within your current shell (only)

setenv ..defines global variables (i.e. the subshells will know them)


Wolfgang Sander-Beuermann zz...@kursix.rrzn.uni-hannover.de

Dave Eisen

unread,
Jan 22, 1993, 12:27:45 PM1/22/93
to
In article <1993Jan22....@newsserver.rrzn.uni-hannover.de> zz...@kursix.rrzn.uni-hannover.de (Wolfgang Sander-Beuermann) writes:
>
> set ... defines variables within your current shell (only)
>
> setenv ..defines global variables (i.e. the subshells will know them)
>

Not just subshells. Any program you run will know them as well.
Use set for things the shell needs to know about and setenv for
things like PATH, MAIL, TERM, and VISUAL that programs you invoke
need to know about.

--
Dave Eisen Sequoia Peripherals: (415) 967-5644
dke...@leland.Stanford.EDU Home: (415) 321-5154
There's something in my library to offend everybody.
--- Washington Coalition Against Censorship

0 new messages