UNIX FAQ Version 2.1 92/12/04 -- Question 5.5
UNIX FAQ Version 2.1 92/12/04 -- Question 5.5
How can I tell if I am running an interactive shell?
From: wicks@dcdmjw.fnal.gov (Matthew Wicks)
From: dws@ssec.wisc.edu (DaviD W. Sanderson)
Date: Fri, 23 Oct 92 11:59:19 -0600
In the C shell category, look for the variable $prompt.
In the Bourne shell category, you can look for the variable $PS1,
however, it is better to check the variable $-. If $- contains
an 'i', the shell is interactive. Test like so:
case $- in
*i*) # do things for interactive shell
;;
*) # do things for non-interactive shell
;;
esac