[lug] Idea for a new tutorial....maybe???

PC Drew drewpc at colorado.edu
Sat Apr 8 18:16:07 MDT 2000


Before I go into environment variables, I'll take a step back and give
a little background.

What's a shell?  (i.e. sh, ksh, bash, tcsh, csh, etc.)
A shell is a program that lives in user-land (it's built in to the
system) and gives the user a "nice" interface to the kernel.  The
shell provides the most basic feature: you can type in the location of a
program and it forks off a process, then executes that program.

Along with that feature, it provides some niceties.  One of those
things are environment variables.  When you log in to a system, an
environment get's created for you.  This environment gets created
through a number of configuration files: .*rc, .login, .profile, and
the system defaults.  You can think of an environment in UNIX as being
similar to earth's environment (okay, it's a stretch, but bare with
me...).  If you change one thing in the environment, it may or may not
effect the rest of the environment.  If you change the color of the
sky, it might not matter.  If you take the oxygen out of the air, then
when people try to breath, they won't get the oxygen that they need
and they'd die.  If they didn't try to breath, then nothing would
happen to them.

An environment variable in UNIX is similar.  If you change your path,
it won't matter until you try to use it (i.e. try to run a program).
When you do run a program, that instance of the program get's a copy
of your environment.  This way, it can use your path or any other
variable it needs.  To set an environment variable (in tcsh anyway),
you use the command "setenv".  You can also have shell variables that
are variables only for that instance of the shell.  These variables
don't get passed to any programs.  When writing scripts, it's
preferable to use shell variables.  Otherwise, use environment
variables. To set shell variables, you use the command "set" instead
of "setenv".

This is all well and good, but how do you save a certain environment
variable?  Let's say you change your path to include "/usr/local/bin"
by calling "setenv".  That's fine, until you exit your terminal
window.  If you only wanted to temporarily add that to your path, then
everything's dandy.  If you wanted to permanently change it, you
should put that command into your .*rc file (i.e. .tcshrc for tcsh).

Like editors, shells are very controversial.  I personally like tcsh
the best.  Lot's of sys admins like bash a lot.  Just like I think you
should learn a little bit about vi, I think that everyone should learn
about the "sh" shell.  That's the default root shell on systems like
Solaris (usually denoted by the "#" at the prompt).  Also, most shell
scripts are written in sh because it's installed on every machine!

That's all I have, if you've got more questions then feel free to post
them!  Also, if I've said anything wrong, please correct me.


--
PC Drew


Thus spake John Starkey on Saturday, April 08, 2000, 4:21:39 PM:


JS> Not to flood the group right now. This is message 5 I think.

JS> But could someone put together an explanation of the "environment
JS> variable". I keep hearing about setting up your environment.

JS> What's that all about. I assume it has a lot to do with the .*rc files.
JS> And I have a feeling that I'm working with the variables all the time but
JS> I don't really understand the term.

JS> Thanks.

JS> John



JS> _______________________________________________
JS> Web Page:  http://lug.boulder.co.us
JS> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug






More information about the LUG mailing list