How tell if ksh interactive?

How tell if ksh interactive?

Post by Vijay S. Baj » Wed, 10 Apr 1996 04:00:00



In my .kshrc I would like to know if the shell "dotting" me in is
interactive or batch. Depending on this switch I'll either print
a prompt or not, or a title to an xterm window. Basically if you do
a set -o it prints a list of options, so you grep for interactive
and look for on or off. Is there another way?

Thanks!
Vijay Bajwa

 
 
 

How tell if ksh interactive?

Post by Stanislaw Streln » Tue, 16 Apr 1996 04:00:00



: In my .kshrc I would like to know if the shell "dotting" me in is
: interactive or batch. Depending on this switch I'll either print
: a prompt or not, or a title to an xterm window. Basically if you do
: a set -o it prints a list of options, so you grep for interactive
: and look for on or off. Is there another way?

: Thanks!
: Vijay Bajwa

if [ "$USER" = "" -o "$PS1" = "" ]; then
     #should be non-interactive
else
     #should be interactive
fi

--

          St.Strelnik

Do what comes naturally now.  Seethe and fume and throw a tantrum.

 
 
 

How tell if ksh interactive?

Post by David Moo » Wed, 17 Apr 1996 04:00:00



Quote:>In my .kshrc I would like to know if the shell "dotting" me in is
>interactive or batch. Depending on this switch I'll either print
>a prompt or not, or a title to an xterm window. Basically if you do
>a set -o it prints a list of options, so you grep for interactive
>and look for on or off. Is there another way?

'test -t 0' will tell you if the standard input is attached
to a terminal.

if test -t 0
then
    echo "Prompt: \c"
fi

read answer

--
======================
David A. Moore

 
 
 

How tell if ksh interactive?

Post by Heiner Stev » Thu, 25 Apr 1996 04:00:00



 > In my .kshrc I would like to know if the shell "dotting" me in
 > is interactive or batch. Depending on this switch I'll either
 > print a prompt or not, or a title to an xterm window. Basically
 > if you do a set -o it prints a list of options, so you grep for
 > interactive and look for on or off. Is there another way?

The preset variable $- contains the ksh invocation flags.
Example:

    $ print $-
    ism

If the output contains an "i" the shell is interactive.

if [[ $- = *i* ]]
then
    print Shell is interactive
else
    print Shell is NOT interactive
fi

Heiner
--
     -------------------------------------------------------------

   / BinTec Computersysteme GmbH / mine, not BinTec's --       /
  / Willstaetter Str. 30 ------- ...even if they should be ;-)/

------------------------------------------------------------

 
 
 

1. HOW do you tell KSH is interactive ?

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

2. Linux on netzero??

3. IFS in ksh and sh

4. Does Apache have agent_log and refer_log ??

5. ksh Quoting and IFS Question

6. Kernel panic: trying to free up swapper space...Help!!!

7. ksh - problem with resetting the IFS

8. Setting up SLIP with Linux (problems with route command)

9. ksh/sh difference w/IFS or read??

10. two ifs after a then, possible (ksh)?

11. ksh: Setting IFS to newline

12. ksh - Where and How is IFS init?

13. .kshrc execution in interactive ksh shell