GNU Info

Info Node: (bashref.info)Is this Shell Interactive?

(bashref.info)Is this Shell Interactive?


Next: Interactive Shell Behavior Prev: What is an Interactive Shell? Up: Interactive Shells
Enter node , (file) or (file)node

Is this Shell Interactive?
--------------------------

   To determine within a startup script whether or not Bash is running
interactively, test the value of the `-' special parameter.  It
contains `i' when the shell is interactive.  For example:

     case "$-" in
     *i*)	echo This shell is interactive ;;
     *)	echo This shell is not interactive ;;
     esac

   Alternatively, startup scripts may examine the variable `PS1'; it is
unset in non-interactive shells, and set in interactive shells.  Thus:

     if [ -z "$PS1" ]; then
             echo This shell is not interactive
     else
             echo This shell is interactive
     fi


automatically generated by info2www version 1.2.2.9