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".
2. Where are the environment variables stored? Is it in the same pplace
as other variables or not?
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?
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.
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.
I guess this is enough for now. Let me add that there could be some
silly questions above due to the fact that I am not a pro in shell
programming or anything. But, your responses to all or some of the
above will be greatly appreciated whether sent directly to me or to
the net. Thank you all in advance.
-- Srini
(ncsrini at ndsuvax or ncsrini at plains.NoDak.edu )
(nu104046 at ndsuvm1 -- BITNET)
>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
Built-in commands recognized by csh are duplicated as zero-length
files in /usr/lib/builtins/. (There is no corresponding directory for
sh or ksh; the files in builtins/ are strictly for csh.)
-- bd
In the old days when everyone just logged into a terminal it was easier
to decide whether settings of various things should go in .login or
.cshrc. However, in the days of networked window systems things can get
a little messier. At the last place I worked it was quite common to
use rsh to start an xterm running csh on a remote machine with output
directed to the local machine's X server. This gives you the strange
situation of having a csh that is not the child of a login shell.
Therefore you had to set things like environment variables that
would otherwise be inherited from a login shell in .cshrc.
--
Scott Wilson arpa: swi...@sun.com
Sun Microsystems uucp: ...!sun!swilson
Mt. View, CA
[Some stuff about the C-shell]
>>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.
Not every time it starts up -- see below.
>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...
The .login is not sourced on every csh startup (e.g. when starting a new
xterm window), but only those for which the first char of argv[0] is a
hyphen (this denotes a login shell). Csh can, however, be told to source
the .login file by having the first char be a hyphen.
Chet Ramey
ch...@cwjcc.CWRU.EDU
| Chet Ramey ch...@cwjcc.CWRU.EDU ch...@alpha.CES.CWRU.EDU
|
| "It is, it is a glorious thing to be a pirate king"
The UNIX(tm) C SHELL fiel Guide by Anderson & Anderson (Prentice Hall, 1986)
--
"Les jours de pluie ... etc ... "
se...@imag.imag.fr se...@imag.UUCP uunet.uu.net!imag!serge
Rouveyrol Serge,Laboratoire L.G.I,BP 53,38041 Grenoble , CEDEX , FRANCE
-- bd
Please, people, qualify questions and answers with a system type, or at
least general family. I've never heard of /usr/lib/builtins and
neither have our machines (most of them BSD). (Unless, of course, the
question or answer is inherently specific, such as "what's the BSD
analog of VMIN and VTIME".)
As far as I know, BSD doesn't have files anywhere corresponding to
shell builtins (sh, csh, foosh, it matters not). Some things which are
built into some shells but not others exist as programs for the benefit
of the shells into which they are not built, but that's about it.
der Mouse
old: mcgill-vision!mouse
new: mo...@larry.mcrcim.mcgill.edu
(To stave off the flood: BSD has no direct analogs of VMIN and VTIME.)
You have your direction backwards: The set of changes to csh which
employ things like /usr/lib/builtins *originated* at HP via CMU. The
base of such changes was the tenex.c module distributed around Usenet
in October 1983 by Ken Greer of HP Labs, which includes the comment:
/*
* Tenex style file name recognition, .. and more.
* History:
* Author: Ken Greer, Sept. 1975, CMU.
* Finally got around to adding to the Cshell., Ken Greer, Dec. 1981.
*
* Search and recognition of command names (in addition to file names)
* by Mike Ellis, Fairchild A.I. Labs, Sept 1983.
*/
--Karl
(BTW, Ken Greer is no longer at HP Labs. He's the driving force
behind Elan Computer Group, the troff folks.)
-- bd