Operating System - HP-UX
1826592 Members
3754 Online
109695 Solutions
New Discussion

how to tell if the shell is interactive within a ksh shell script

 
SOLVED
Go to solution
curt larson
Frequent Advisor

how to tell if the shell is interactive within a ksh shell script

How do you test if your shell (ksh) is interactive? i.e. the shell is attached to a teminal for i/o, such as when your logged on. And opposed to a shell being run by cron, etc.

I know there is an easier way then doing a set -o and checking if the interactive option is set to "on".
nobody else has this problem
3 REPLIES 3
Victor BERRIDGE
Honored Contributor
Solution

Re: how to tell if the shell is interactive within a ksh shell script

Test it:
If tty -s ....

Regards
Victor
Brian M. Fisher
Honored Contributor

Re: how to tell if the shell is interactive within a ksh shell script

Maybe this is what you are looking for:
Checking if shell is interactive HP document#
W3454520
http://us-support.external.hp.com/cki/bin/doc.pl/

The correct way to check if the shell is interactive (at least in ksh)
is by checking $-.

case $- in
*i*) echo interactive ;;
*) echo not interactive ;;
esac


Brian
<*(((>< er
Perception IS Reality
James R. Ferguson
Acclaimed Contributor

Re: how to tell if the shell is interactive within a ksh shell script

Curt:

if [ -t -eq 0 ]
then
echo "i'm interactive"
else
echo "not interactive"
fi

...JRF...