[comp.sys.next] Running .cshrc

fletcher@socrates.umd.edu (Charles Fletcher) (05/17/91)

I'm Baaaaaaaaaaaaccccccccckkkkkkkkkkkkk!!!!!!!!!!!!

After being away from the net for awhile I now have an account which
will post news. So here's my first return question:

I know the .cshrc file is run when I start up terminal (since I still
run csh--got to get some time to look at bash). But at what other
times is it invoked. I would say "it isn't". However, it runs when
I use 'which', it runs when I print from TeXview, and probably at other
times.

How do I know this?--Because I put some commands in the .cshrc file
to power down the printer and set the background. Now at odd times
(like running 'which') the printer goes on and off and the background
flashs.

Why do I care?--Because I don't like my printer going on and off and
my background flashing!

Anyone got any idea why this happens and what to do about it?

Thanks,
Charlie
fletcher@socrates.umd.edu
cwf@math.umd.edu

zimmer@calvin.stanford.edu (Andrew Zimmerman) (05/18/91)

In article <1991May17.125630.2977@socrates.umd.edu> fletcher@socrates.umd.edu (Charles Fletcher) writes:
>
>I'm Baaaaaaaaaaaaccccccccckkkkkkkkkkkkk!!!!!!!!!!!!
>
>After being away from the net for awhile I now have an account which
>will post news. So here's my first return question:
>
>I know the .cshrc file is run when I start up terminal (since I still
>run csh--got to get some time to look at bash). But at what other
>times is it invoked. I would say "it isn't". However, it runs when
>I use 'which', it runs when I print from TeXview, and probably at other
>times.
>

    The which command in /usr/ucb/which is a shell script, and as you
mentioned, it does run your .cshrc.   

   1.  Why does which use #!/bin/csh -f, and then go and source ~/.cshrc.
       What is the difference between that and just doing a #!/bin/csh?
   2.  If you take out the line that sources ~/.cshrc at the very least,
       which has problems with telling you about aliases.
   3.  You might be able to fix the problem you are having by changing your
       .cshrc.

        if(! $?0) then 
	# the code in this section will only be run if csh doesn't know the
        # current input filename.  This code will not be run when you
        # do the which command.
        # this is where you could put you background and printer power
	# commands
	endif


    I have tried the code I mention in part 3, and it seems to work.  However,
I am not a shell guru, and it might not work for all cases, or there might
be an easier method.

Andrew
zimmer@calvin.stanford.edu

glenn@heaven.woodside.ca.us (Glenn Reid) (05/18/91)

Charles Fletcher writes
> I know the .cshrc file is run when I start up terminal

> Why do I care?--Because I don't like my printer going on and off and
> my background flashing!
> 
> Anyone got any idea why this happens and what to do about it?

Put these commands in .login instead of .cshrc.  .login is only read
when you start up a login shell, not a subshell, and is more appropriate
for that kind of commands.

--
 Glenn Reid				RightBrain Software
 glenn@heaven.woodside.ca.us		NeXT/PostScript developers
 ..{adobe,next}!heaven!glenn		415-326-2974 (NeXTfax 326-2977)

scott@erick.gac.edu (Scott Hess) (05/18/91)

In article <1991May17.125630.2977@socrates.umd.edu> fletcher@socrates.umd.edu (Charles Fletcher) writes:
   How do I know this?--Because I put some commands in the .cshrc file
   to power down the printer and set the background. Now at odd times
   (like running 'which') the printer goes on and off and the background
   flashs.

   Why do I care?--Because I don't like my printer going on and off and
   my background flashing!

   Anyone got any idea why this happens and what to do about it?

.cshrc is run anytime a csh is run (or tcsh, or some other csh
variant).

Now, there are other special files.  For instance .login.  This
is run under a special type of csh - a login shell.  Then, it
first sources the .cshrc, then the .login file.  Generally,
login shells are only invoked from from tty logins, or network
logins, or (luckly enough), from Terminal or Stuart logins.

So, maybe you could move the commands into your .login file,
and mark SourceDotLogin in Stuart or Terminal (in Stuart,
it's the "Shell reads .login file" switch in Preferences).

Later,
--
scott hess                      scott@gac.edu
Independent NeXT Developer	GAC Undergrad	<almost out!>
<I still speak for nobody>

danno@css.itd.umich.edu (Daniel T. Pritts) (05/19/91)

In article <SCOTT.91May18103337@erick.gac.edu> scott@erick.gac.edu (Scott Hess) writes:
>.cshrc is run anytime a csh is run (or tcsh, or some other csh
>variant).
>
>Now, there are other special files.  For instance .login.  This
>is run under a special type of csh - a login shell.  Then, it
>first sources the .cshrc, then the .login file.  Generally,
>login shells are only invoked from from tty logins, or network
>logins, or (luckly enough), from Terminal or Stuart logins.
>

On a related note, does anyone know of a way for a user to have the
equivalent of a .login for when they login to a NeXT on console (using
the normal login panel?  I know about the hooks on the login process
in etc/ttys, but those are only for blanket usage...i.e. anyone who logs
in gets the same stuff.  I want this to be customizable...
 
email or post replies.  thanks ...

dan pritts   danno@um.cc.umich.edu  USERDANO@UMICHUM

fletcher@socrates.umd.edu (Charles Fletcher) (05/20/91)

In article <506@heaven.woodside.ca.us> glenn@heaven.woodside.ca.us (Glenn Reid) writes:
>I wrote
>> I know the .cshrc file is run when I start up terminal
>> Why do I care?--Because I don't like my printer going on and off and
>> my background flashing!

>Put these commands in .login instead of .cshrc.  .login is only read
>when you start up a login shell, not a subshell, and is more appropriate
>for that kind of commands.
>
>--
> Glenn Reid				RightBrain Software
> glenn@heaven.woodside.ca.us		NeXT/PostScript developers
> ..{adobe,next}!heaven!glenn		415-326-2974 (NeXTfax 326-2977)


Thanks to Glenn and everyone else for the help. I received to many
replies to thanks everyone individually, so this is a group THANKS.
It seems I'm the only one who has been using UNIX for several years
and didn't realize that the .cshrc file is run *every* time a shell 
script is run. Ideas for the printer off are covered in FAQ.

Thanks again,
Charlie
fletcher@socrates.umd.edu

mycroft@kropotki.gnu.ai.mit.edu (Charles Hannum) (05/24/91)

In article <1991May17.125630.2977@socrates.umd.edu> fletcher@socrates.umd.edu (Charles Fletcher) writes:

   After being away from the net for awhile I now have an account which
   will post news. So here's my first return question:

   I know the .cshrc file is run when I start up terminal (since I still
   run csh--got to get some time to look at bash). But at what other
   times is it invoked. I would say "it isn't". However, it runs when
   I use 'which', it runs when I print from TeXview, and probably at other
   times.

   Anyone got any idea why this happens and what to do about it?

I quote from the man page for which(1) (and, admittedly, I'm using an HP right
now, so the NeXT's is sure to be more recent ;-/)

          Both aliases and path are determined by sourcing (executing)
          the user's .cshrc file.

As for TeXview, I have no idea why it runs your .cshrc.  Someone probably
forgot to give csh a '-f' somewhere.

Now, how do we fix this?

Since presumable you'll still want which(1) to work, set your path, environment
variables, and aliases first, and then insert the following:

	  if (! $?prompt) exit

Why?  If csh is run interactively, it defines a shell variable 'prompt' which
holds (of course) the current prompt.  If run non-interactively, and assuming
you haven't defined it yourself elsewhere, it will be undefined and thus the
above statement will cause your .cshrc to exit.