[comp.unix.wizards] SYS V Bourne Shell .shrc file

mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) (12/22/89)

While hacking around trying to include some difficult functionality
for a program I was writing,  I examined /bin/sh with a binary
display program looking for undocumented options.  Instead,  I ran
into the string .shrc.  Intrigued,  I quickly formulated a .shrc file
in my home directory to echo Hello, world!.  After that,  when I forked
to the shell,  I got the message,  providing it was an interactive
shell (if you pipe to the shell,  for instance to unshar a file,  or using
the vi !! command,  it is not invoked).  The .shrc is also invoked
prior to /etc/profile and ~/.profile on login.  Since I use my
.shrc to invoke my shell functions and much of the functionality
that I already do in .profile,  I check for the existence of a
shell environment variable I set in .profile and only execute it
if it already exists.  Of course,  as with .profile,  do not
place any exits in the file.

I am system administer on two boxes,  so I use my prompt to indicate
which box I'm on,  what line,  the depth of my shell nesting,  and
my current working directory.  Really cuts down on the confusion,
since I'm frequently on both boxes simultaneously,  often on
multiple lines (we're testing out Token Ring software connecting
the two boxes,  so I may be kermitted from one box to the other
over a direct asynch line,  the nloginned back to the original
box via Token Ring.

One of the truly wonderful things,  it's invoked under su as well.
I just check to see if PS1 == '# ' (don't forget space),  I reset
my path to something reasonable,  instead of the annoying and
insecure :/etc:/bin:/usr/bin.

I already know this capability does not exist on SUN OS3.5.

Other SYSV users,  let me know if you have it.

Our system consists of two NCR Towers running SYSVR1 and SYSVR2 and
I have confirmed it's existence on another Tower running SYSVR3.2.


-- 

Dan Mercer
Reply-To: mercer@ncrcce.StPaul.NCR.COM (Dan Mercer)

daveb@i88.isc.com (Dave Burton) (12/23/89)

In article <1792@ncrcce.StPaul.NCR.COM> mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) writes:
|... I examined /bin/sh with a binary
|display program looking for undocumented options.  Instead,  I ran
|into the string .shrc. ....
|Other SYSV users,  let me know if you have it.
|Our system consists of two NCR Towers running SYSVR1 and SYSVR2 and
|I have confirmed it's existence on another Tower running SYSVR3.2.

The SVR3.2 sources from AT&T do not have any .shrc processing; only .profile
and /etc/profile are supported. Any sh that has .shrc has been modified by the
vendor and therefore (the use of .shrc) is non-portable.
--
Dave Burton
uunet!ism780c!laidbak!daveb

wescott@Columbia.NCR.COM (Mike Wescott) (12/27/89)

In article <1792@ncrcce.StPaul.NCR.COM> mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) writes:
> The .shrc is also invoked prior to /etc/profile and ~/.profile on login.

Nope.  After /etc/profile but before $HOME/.profile, mimicing csh's behavior.

> Other SYSV users,  let me know if you have it.

This is an NCR hack. If someone else has it, they've reimplemented it
independently.  I hacked it into /bin/sh as a mechanism to export shell
funtions against the day we get ksh.

--
	-Mike Wescott
	 mike.wescott@ncrcae.Columbia.NCR.COM

mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) (12/27/89)

In article <1864@sauron.Columbia.NCR.COM> wescott@micky.Columbia.NCR.COM (Mike Wescott) writes:
:In article <1792@ncrcce.StPaul.NCR.COM> mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) writes:
:> The .shrc is also invoked prior to /etc/profile and ~/.profile on login.
:
:Nope.  After /etc/profile but before $HOME/.profile, mimicing csh's behavior.
:
:> Other SYSV users,  let me know if you have it.
:
:This is an NCR hack. If someone else has it, they've reimplemented it
:independently.  I hacked it into /bin/sh as a mechanism to export shell
:funtions against the day we get ksh.
:
:--
:	-Mike Wescott
:	 mike.wescott@ncrcae.Columbia.NCR.COM

Well,  I for one really appreciate it,  since I use shell functions
excessively.   In fact,  I have one problem that I think is function
dependent - in using a shell function that changes directories (so that
my prompt shows my current directory) I occassionaly hang.  Characters
still echo,  but nothing happens.

Any clues.  Any more undocumented hacks.  And how did you ever slip
something past management?  Certainly not by telling them you were
making something more user friendly.


-- 

Dan Mercer
Reply-To: mercer@ncrcce.StPaul.NCR.COM (Dan Mercer)

davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) (12/27/89)

  Multiple startups are interesting. Since I have several maintenance
logins on machines I administrate, and must sometimes use sh rather than
ksh, I have my hierarchy set up like this:
	.profile ends with:
		if [ -f .kshrc ]; then ENV=$HOME/.kshrc; fi
	.kshrc ends with:
		if [ -f local.ksh ]; then . ./local.ksh; fi

  Then in the maintenance logins the profile is ". /u/staff/davidsen/.profile"
and the .kshrc is ". ~davidsen/.kshrc". The local.ksh is always tailored
to the needs of the id under which I'm operating. This allows me to
define a large set of aliases, macros, and symbols to keep a consistent
user interface, while still allowing me in if for some reason sh is
being used.
-- 
bill davidsen	(davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon

forrie@suntau.UUCP (Forrie Aldrich) (12/28/89)

If we are on a somewhat standard (standard?  what's that??!! :-) ) shell,
how can be patch sh to use the .shrc?

Or IS there a way?

Forrie

-- 
.---------------------------------------------------------------------_   /|--.
|  Forrie Aldrich   (forrie@suntau.UUCP - root@suntau.UUCP)           \'o.O'  |
|                                                                     =()_()= |
|  Email:  uunet!zinn.mv.com!eci!suntau!forrie                           U    |
|          uunet!unhd!unhtel!suntau!forrie                                    |
.-----------------------------------------------------------------------------.

gwyn@smoke.BRL.MIL (Doug Gwyn) (01/05/90)

In article <1864@sauron.Columbia.NCR.COM> wescott@micky.Columbia.NCR.COM (Mike Wescott) writes:
>In article <1792@ncrcce.StPaul.NCR.COM> mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) writes:
>> The .shrc is also invoked prior to /etc/profile and ~/.profile on login.
>Nope.  After /etc/profile but before $HOME/.profile, mimicing csh's behavior.

Ugh -- it was obviously the wrong way around in csh, so why mimic that??

When we added support for $ENV in the BRL Bourne shell (more general than
.shrc, also doesn't require disabling in non-interactive uses such as
shell scripts), we did it right.

allbery@NCoast.ORG (Brandon S. Allbery) (01/08/90)

As quoted from <11888@smoke.BRL.MIL> by gwyn@smoke.BRL.MIL (Doug Gwyn):
+---------------
| In article <1864@sauron.Columbia.NCR.COM> wescott@micky.Columbia.NCR.COM (Mike Wescott) writes:
| >In article <1792@ncrcce.StPaul.NCR.COM> mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) writes:
| >> The .shrc is also invoked prior to /etc/profile and ~/.profile on login.
| >Nope.  After /etc/profile but before $HOME/.profile, mimicing csh's behavior.
| 
| Ugh -- it was obviously the wrong way around in csh, so why mimic that??
+---------------

I think the csh behavior cited above is more correct.  I've gotten sick of
kluging around Altos's csh, which invokes .cshrc before /etc/cshrc -- I set my
histchars to ^@ so I can use ! without having to remember to backslash it (I
do a lot of UUCP) and I *always* have to arrange for it to not be set if it's
a login shell, because /etc/cshrc usually contains a line like "stty kill ^u"
(Altos's default is ^X, ugh).  Boo, hiss.  Besides which, the user shouldn't
be given the opportunity to alter what /etc/cshrc does; if .cshrc is run
forst, the user can drop an alias in place of one of the commands in
/etc/cshrc.  (It's not a security hole, but it *can* violate the Principle of
Least Surprise.)

++Brandon
-- 
Brandon S. Allbery    allbery@NCoast.ORG, BALLBERY (MCI Mail), ALLBERY (Delphi)
      uunet!cwjcc.cwru.edu!ncoast!allbery ncoast!allbery@cwjcc.cwru.edu
*(comp.sources.misc mail to comp-sources-misc[-request]@backbone.site, please)*
*Third party vote-collection service: send mail to allbery@uunet.uu.net (ONLY)*

ti@altos86.Altos.COM (Ti Kan) (01/12/90)

In article <1990Jan7.175807.13054@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery) writes:
>I think the csh behavior cited above is more correct.  I've gotten sick of
>kluging around Altos's csh, which invokes .cshrc before /etc/cshrc

I don't know what version of our System V on what hardware platform you have,
but I have checked our csh under Altos System V on the Altos 80386 series 600,
1000 and 2000 as well as the Altos 80486 series 1000, and all of it invokes
$HOME/.cshrc *after* /etc/cshrc.

>a login shell, because /etc/cshrc usually contains a line like "stty kill ^u"
>(Altos's default is ^X, ugh).  Boo, hiss.

Ctrl-X is a semi-standard kill character, as is Ctrl-U.  The standard kill
character dating back to who-knows-when is @ (would you use that?).  Stty
allows you to set it to anything you want, so this shouldn't be a problem.

>Besides which, the user shouldn't
>be given the opportunity to alter what /etc/cshrc does; if .cshrc is run
>forst, the user can drop an alias in place of one of the commands in
>/etc/cshrc.  (It's not a security hole, but it *can* violate the Principle of
>Least Surprise.)
>Brandon S. Allbery    allbery@NCoast.ORG, BALLBERY (MCI Mail), ALLBERY (Delphi)

I agree with you.  But, like I said, I found our csh to behave correctly
in this regard.

-Ti
-- 
Ti Kan                                                                  \\\
vorsprung durch technik!                                                 \\\
Internet: ti@altos.com                                                /// \\\
UUCP: ...!uunet!altos!ti                                             ////////\

gwyn@smoke.BRL.MIL (Doug Gwyn) (01/13/90)

In article <1990Jan7.175807.13054@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery) writes:
>As quoted from <11888@smoke.BRL.MIL> by gwyn@smoke.BRL.MIL (Doug Gwyn):
>| In article <1864@sauron.Columbia.NCR.COM> wescott@micky.Columbia.NCR.COM (Mike Wescott) writes:
>| >In article <1792@ncrcce.StPaul.NCR.COM> mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) writes:
>| >> The .shrc is also invoked prior to /etc/profile and ~/.profile on login.
>| >Nope.  After /etc/profile but before $HOME/.profile, mimicing csh's behavior.
>| Ugh -- it was obviously the wrong way around in csh, so why mimic that??
>I think the csh behavior cited above is more correct.  I've gotten sick of
>kluging around Altos's csh, which invokes .cshrc before /etc/cshrc

Certainly /etc/profile should be sourced before ~/.profile.
There should NOT be a /etc/shrc at all, and ~/.shrc (or better,
the file specified by the ENV environment variable) should be
sourced ONLY for an interactive shell and after ~/.profile for
a login shell.

Shell features should not be added as isolated items, but rather
designed carefully to work together.  We use the above approach
at BRL to provide extremely spiffy user environments both with
and without multiple windows.

allbery@NCoast.ORG (Brandon S. Allbery) (01/14/90)

As quoted from <154@altos86.Altos.COM> by ti@altos86.Altos.COM (Ti Kan):
+---------------
| In article <1990Jan7.175807.13054@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery) writes:
| >I think the csh behavior cited above is more correct.  I've gotten sick of
| >kluging around Altos's csh, which invokes .cshrc before /etc/cshrc
| 
| I don't know what version of our System V on what hardware platform you have,
| but I have checked our csh under Altos System V on the Altos 80386 series 600,
+---------------

It may have been the older ones (286 and/or Series 2000 Xenix) that had the
bug; I haven't tested it recently, since I dislike having my logins blow up on
me.  Getting a failed history substitution on login can produce results
ranging from being dumped into a plain vanilla csh to being completely unable
to log in, depending on what commands are run.  If you *did* fix this, I thank
you.

+---------------
| >(Altos's default is ^X, ugh).  Boo, hiss.
| 
| Ctrl-X is a semi-standard kill character, as is Ctrl-U.  The standard kill
| character dating back to who-knows-when is @ (would you use that?).  Stty
| allows you to set it to anything you want, so this shouldn't be a problem.
+---------------

I occasionally have to; although they have to drag me kicking and screaming to
work on 3B/2's....  We *do* change it, which is the problem---we say "stty
kill ^u" in /etc/cshrc and it blows up (or at least used to) if I do my usual
"set histchars=^@" in my .cshrc.

I'll check the 386 csh; if it is in fact fixed, I thank you.  The previous
behavior was rather annoying....

++Brandon
-- 
Brandon S. Allbery    allbery@NCoast.ORG, BALLBERY (MCI Mail), ALLBERY (Delphi)
      uunet!cwjcc.cwru.edu!ncoast!allbery ncoast!allbery@cwjcc.cwru.edu
*(comp.sources.misc mail to comp-sources-misc[-request]@backbone.site, please)*
*Third party vote-collection service: send mail to allbery@uunet.uu.net (ONLY)*