[comp.unix.shell] HOW do you tell KSH is interactive ?

luj@gus17.ecn.purdue.edu (Jun Lu) (02/18/91)

In my .profile I set "export ENV=~/.kshrc".  Certainly I don't want
the aliases or something to executed for non-interactive shell, i.e.
the shell spawned to interprete the ksh-scripts.  Is there a way to 
tell if the shell is interactive wone ithin .kshrc ?

Thanks,
--Jun
P.S. testing PS1 didn't work.  
--
-- Jun Lu                          Internet:luj@ecn.purdue.edu          --
-- Aeronautics & Astronautics      Bitnet:  luj%ecn.purdue.edu@purccvm  --
-- Purdue University		   UUCP:    pur-ee!luj                  -- 
-- W. Lafayette, IN 47907          Phone:317-494-9410  Fax:317-494-0307 --

spaf@cs.purdue.EDU (Gene Spafford) (02/18/91)

If you only want to do something if you are interactive, then put the
following at the appropriate places in your $ENV file:

if [[ $- = *i* ]]
then
    do stuff for interactive here
fi
-- 
Gene Spafford
NSF/Purdue/U of Florida  Software Engineering Research Center,
Dept. of Computer Sciences, Purdue University, W. Lafayette IN 47907-2004
Internet:  spaf@cs.purdue.edu	phone:  (317) 494-7825

asg@sage.cc.purdue.edu (The Grand Master) (02/19/91)

In article <1991Feb18.070424.6054@noose.ecn.purdue.edu> you write:
>In my .profile I set "export ENV=~/.kshrc".  Certainly I don't want
>the aliases or something to executed for non-interactive shell, i.e.
>the shell spawned to interprete the ksh-scripts.  Is there a way to 
>tell if the shell is interactive wone ithin .kshrc ?
>
>Thanks,
>--Jun
>P.S. testing PS1 didn't work.  
>--
>-- Jun Lu                          Internet:luj@ecn.purdue.edu          --
>-- Aeronautics & Astronautics      Bitnet:  luj%ecn.purdue.edu@purccvm  --
>-- Purdue University		   UUCP:    pur-ee!luj                  -- 
>-- W. Lafayette, IN 47907          Phone:317-494-9410  Fax:317-494-0307 --

Get ready, this is really weird:
put these two lines in your .profile:


START=$HOME/.kshrc
ENV='${START[ (_$- = 1) + (_ = 0) - (_$- != _${-%%*i*}) ]}'
export START ENV
 
		Bruce Varney
		  The Grand Master

bernie@metapro.DIALix.oz.au (Bernd Felsche) (02/26/91)

You could test to see if stdin is connceted to a tty!

[ -t 0 ] && echo interactive
-- 
Bernd Felsche,                 _--_|\   #include <std/disclaimer.h>
Metapro Systems,              / sale \  Fax:   +61 9 472 3337
328 Albany Highway,           \_.--._/  Phone: +61 9 362 9355
Victoria Park,  Western Australia   v   Email: bernie@metapro.DIALix.oz.au

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (02/26/91)

As quoted from <5864@iron6.UUCP> by yeates@motcid.UUCP (Tony J Yeates):
+---------------
| asg@sage.cc.purdue.edu (The Grand Master) writes:
| >In article <1991Feb18.070424.6054@noose.ecn.purdue.edu> you write:
| >> Certainly I don't want
| >>the aliases or something to executed for non-interactive shell, i.e.
| >>the shell spawned to interprete the ksh-scripts.  
| 
| Starting ksh scripts with the the -p option in your shell scripts might help,
| on Sun we use the first line:-
+---------------

case "x$-" in
x*i*)
    # interactive
    ;;
*)  # non-interactive
    ;;
esac

This has the advantage over [[ ]] that, should it be necessary, this is also
legal Bourne shell syntax.  (Why would you need this in Bourne shell?  For
"scripts" that you "." (that's "source" for you csh-noids :-) from interactive
and non-interactive shells and need different behavior from each.)

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY

luj@gus17.ecn.purdue.edu (Jun Lu) (03/01/91)

In article <1991Feb26.041034.15149@metapro.DIALix.oz.au> bernie@metapro.DIALix.oz.au (Bernd Felsche) writes:
>You could test to see if stdin is connceted to a tty!
>
>[ -t 0 ] && echo interactive

Incorrect. You can easily see this by putting this line in a script file.

--
-- Jun Lu                          Internet:luj@ecn.purdue.edu          --
-- Aeronautics & Astronautics      Bitnet:  luj%ecn.purdue.edu@purccvm  --
-- Purdue University               UUCP:    pur-ee!luj                  -- 
-- W. Lafayette, IN 47907          Phone:317-494-9410  Fax:317-494-0307 --

bernie@metapro.DIALix.oz.au (Bernd Felsche) (03/05/91)

In <1991Feb28.183809.23891@noose.ecn.purdue.edu> luj@gus17.ecn.purdue.edu
  (Jun Lu) writes:

>In article <1991Feb26.041034.15149@metapro.DIALix.oz.au> bernie@metapro.DIALix.oz.au (Bernd Felsche) writes:
>>You could test to see if stdin is connceted to a tty!
>>
>>[ -t 0 ] && echo interactive

>Incorrect. You can easily see this by putting this line in a script file.

Now, if I hadn't tried it, I wouldn't have suggested it! It works for
me, and has worked interactively, and via a script. Now, if your
standard input is altered, even by you putting the script in
background (making it non-interactive) then the message won't be
printed.

Maybe you have a broken ksh? The one I have came with SVR3.2/68k
from Motorola. As a matter of fact, it even works with the Bourne
shell we have (as it should, because it's a standard test function).

Can you tell me what I'm doing right? :-)
-- 
Bernd Felsche,                 _--_|\   #include <std/disclaimer.h>
Metapro Systems,              / sale \  Fax:   +61 9 472 3337
328 Albany Highway,           \_.--._/  Phone: +61 9 362 9355
Victoria Park,  Western Australia   v   Email: bernie@metapro.DIALix.oz.au