[vox-tech] checking for interactive shell in bash

Peter Jay Salzman vox-tech@lists.lugod.org
Thu, 25 Jul 2002 12:09:55 -0700


hola,

here's a snippet from my /etc/profile:

   # $TERM is set to "dumb" for scp sessions.
   #
   if [ "$TERM" != "dumb" ]; then
   
      # Stuff for ALL interactive shells
      #
      # Check dir spelling, hash cmds
      shopt -s cdspell checkhash
      # Quiet the console bell
      setterm -bfreq 0
      # No limit to coresizes.
      ulimit -c unlimited
      # Set default file perms as rw-r--r--
      umask 022
      # For ls colors.  nice blinking dangling symlinks!
      eval `dircolors /etc/DIR_COLORS`
   
      # Stuff for non-login shells, like xterms, local and nonlocal
      #
      if [ "$TERM" == "xterm" ]; then
         # Add some extra paths for X
         PATH="$PATH:/usr/X11R6/bin:$HOME/Office52/"
         PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
      fi
   
      # Stuff for local non-login shells (ie local xterms)
      #
      if [ "$DISPLAY" == ":0.0" ]; then
         # Kill the capslock key
         xmodmap -e "remove Lock = Caps_Lock"
         # Turn the X bell off
         xset b off
         # Reset $LINES and $COLUMNS after each command
         shopt -s checkwinsize
      fi
   
   fi

my strategy is this:

   if (any kind of interactive shell at all) {
      do interactive shell stuff (consoles and xterms);

      if (any kind of non-login shell)
         do X-ish stuff (local and non-local);

      if (local non-login shell)
         do X-ish stuff (local only);
   }

the way i check for an interactive shell is by testing $TERM against
"dumb".   i do this because i noticed that scp spawns a shell on the
remote machine and sets TERM to "dumb".

but there are plenty of programs which spawn non-interactive shells, so
i'm thinking that testing against "dumb" isn't the best solution.  it's
specific to scp (i think).

is there a more general way to check for any kind of interactive shell
(both login and non-login)?

hope i got my terminology right...

pete

ps- if anybody has their own hacked bash startup files that they're
proud of, i wouldn't mind seeing what other people are doing.  i could
post mine in its entirety (it's not MUCH longer than what i have above).

-- 
GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D