[net.unix] "Variables" and their settings

wmartin@brl-tgr.ARPA (Will Martin ) (12/04/84)

I'd like some guidance on how variables are set. We've had some discussion
over on net.news about the ORGANIZATION variable, which is used to determine
the info shown in a posting header. It seems that people using csh can do a
"setenv ORGANIZATION "Any old string"" and get it to take on their next
posting, thus leading to random "anonymous" posting info (there was a 
philosophical discussion of this which is unimportant here).

Anyway, I am here on a system running BRL's version of 4.2 BSD, with a 
"plain" shell as my standard shell. I can do all sorts of variable setting
with commands like "TERM=xyz" and "export TERM" and get the terminal type
variable set as needed. However, when I tried doing the same with the
ORGANIZATION variable, it had no effect, until I put that pair of commands
into my .profile file; then it worked.

Correspondents told me to use "set" instead of the straight command
ORGANIZATION="USAMC ALMSA" and exporting that variable. I tried that,
and found that "set" by itself provided a list of variables and how they
were set (was this also resetting anything to the original defaults 
when I ran that?). But I couldn't get a command like:
set ORGANIZATION "USAMC ALMSA" 
to have any effect. (At least that I could see, both with and without
exporting afterwards.)

There doesn't seem to be any manual pages for "set" or "setenv"; at least
not findable by "man set" -- can someone enlighten me on what the differences
are between the ways of setting variables? Why use one versus the other?
It's all rather mysterious. I know of three ways:
1) Use straight VARIABLE=value followed by export VARIABLE commands.
2) Use set VARIABLE value.
3) Use setenv VARIABLE value.

Are there more? #3 works only in csh, right? Do #s 2 & 3 require "export"
comands following them, or is that how they differ from #1?
Why would there be a difference if the variable is set by the .profile
file versus being set in the shell after the login is finished?

Is there an unlimited number of these variables, and do they have to be all
upper-case? Any way to get a listing of them all?

Advice and guidance appreciated!

Regards,
Will Martin

USENET: seismo!brl-bmd!wmartin     or   ARPA/MILNET: wmartin@almsa-1.ARPA

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (12/04/84)

> I'd like some guidance on how variables are set.  ...

I just typed

	ORGANIZATION="USAMC ALMSA" export ORGANIZATION

on the BRL 4.2BSD (both the native and SVR2 Bourne shells) and it worked fine.
This is the proper way to emulate csh's "setenv" while using the Bourne shell.
The "export" command need not be given on the same line as the assignment.
There is no reason that this command would have to be in a .profile to work.
It is always possible that there is a bug in your copy of the shell; if you
have access, you might copy the latest version from either BRL-TGR or BRL-VGR.

"set" shows what is set; it does not set anything.  It is documented in the
manual entry for "sh" (since it is of necessity built into the shell).

"setenv" is the Cshell way of setting environment variables, and its "set"
(not the same as the Bourne shell's!) is used to set "local" shell variables.

> Is there an unlimited number of these variables, and do they have to be all
> upper-case?  Any way to get a listing of them all?

Of course there is some practical limit to ANYthing, but it is sufficiently
large that your need not worry about it on a VAX.  "set" lists them all, as
well as defined "shell functions" (a SVR2 feature).  "export" lists just
those variables that will be added to the "environment", i.e., that are
globally exported to processes run by the shell.  "readonly" lists those
variables that cannot be changed (only works correctly with SVR2 or later).
There is no case restriction on either local shell variables or environment
variables; the use of upper case for environment variables is a convention.