How can I tell if I am running an interactive shell?

How can I tell if I am running an interactive shell?

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



Home FAQ