Shell/Cshell questions

John Ferguson ferg at koko.UUCP
Mon Aug 22 02:54:07 AEST 1988


In article <1145 at ndsuvax.UUCP> ncsrini at ndsuvax.UUCP (srini) writes:
>
>Hello. Some questions on the working of the shell. I am using C shell.
>
>1. When a variable is set, where and how is it kept track of?  Like, is
>   there a symbol table maintained by the shell. Or, is it something
>   else. In any case, can the user access these tables to find out
>   about the variables? The answer to this would probably expplain
>
>   the mechanism of the command "set". 
>
Local shell variables (i.e. those manipulated by 'set' and 'unset') are
kept in dynamically allocated memory by the shell (I can't recall if they
are in a list, tree, whatever -- it isn't important to us).  The only
way to get at them is with the shells builtin commands.  When the command
line is parsed, the shell checks to see if any of the stuff it sees is a
shell variable, alias, shell function (Bourne, KSH), or environment
variable, then does simple substitution.

>2. Where are the environment variables stored? Is it in the same pplace
>   as other variables or not?
>
When a C program starts up, there are actually 3 args to main: argc, argv,
and envp, a pointer to the environment variables.  To quote the V7 manual:
"The shell sh(1) passes an environment entry for each global shell variable
defined when the program is called".  Envp is a pointer to an array of
strings of the form: var=blah.  Check the man pages for exec(2) to see how
to pass the environment pointer to other programs.

>3. What is the exact use of .cshrc and .login? Can one replace the other?
>   If so, what are the side effects? How are the subshells affected by these
>   files?
>
When Csh starts up, it sources the commands in both .cshrc and .login.
Normally .login contains setup information you wish to be active during
the entire life of your login session, such as TERM, PATH, ...  The
.cshrc file is examined for each subsequent invocation of csh, so you
put stuff there which needs to be modified or reset when a subshell
starts up.  Someone else should be able to add more to this...

>4. Can somebody recommend a book or an article that deals with the working   
>   of the shell? I am looking for one that talks about Cshell syntax in
>   detail, also.
>
The UNIX(tm) Shell Programming Language by Manis & Meyer (Sams, 1986) has
some information of csh syntax.  What's the name of that book on csh?  I
personally prefer the csh man pages, which give the whole story, perhaps
more readable than some other man pages ;-)

>5. Where are the pprograms (system) for different commands supppported by
>   a shell usually located in a system? I looked in /bin etc, but couldn't
>   find them.
>
You probably are referring to shell builtins.  I once looked all over for
'cd'.  The shell (whatever one you choose) has certain commands which are
builtin for speed or necessity.  Even though you use them as any other
UNIX command, no subshell is executed.  The work is done by shell code.

   ferg



More information about the Comp.unix.questions mailing list