[sf-lug] printenv "vs." set [was: Re: shell, man(1) [was: ...

Alex Kleider akleider at sonic.net
Sun Aug 21 15:55:03 PDT 2016


On 2016-08-21 11:30, jim wrote:
> I've felt confused about the difference, too.
>     I looked up one site that told me, essentially,
> that the difference between a shell variable and an
> environment variable is that the latter is exported
> while the former is not.
>     I think that's not enough. A shell variable is
> one that the shell creates at the time the shell is
> loaded. Different shells set different variables.


It seems that no variable (shell or environment) can exist except in the 
context of the shell.  So does that make them all shell variables?

There seem to me to be only two ways to distinguish variables:
1. When/how they are created.
2. Whether or not they are inherited (i.e 'export'ed)

One could make an argument that variables can also be classified 
according to 'reason for existence.'  i.e. Does the shell itself need it 
(a 'shell var') or does a programmer set it for her program to use for 
its own reasons (an environment.)  Examples would be
PATH for the shell to be able to do path name completion and PYTHONPATH 
for the python interpreter to know what to do (where to look for 
modules.)

In regards to the latter thought, I've read recently that using the 
environment is no longer recommended practice and config files are a 
better way to achieve the same goal.
I expect use case will determine.

Are these reasonable ideas?








More information about the sf-lug mailing list