multishell user profile

Karl Vogel vogelke+unix at pobox.com
Thu Apr 22 00:33:29 UTC 2010


>> On Wed, 21 Apr 2010 09:53:00 +0200, 
>> Erik Norgaard <norgaard at locolomo.org> said:

E> I need to create a user profile that works in different shells,
E> particularly bash, csh and ksh.  It seems that these does not read the
E> same files and/or in the same order.  So, how do I configure the shell
E> profiles without configuring each shell separately?

   The two things that bite me the most often when switching shells are
   environment variables and aliases.  I keep most of my environment stuff
   in a single file ($HOME/.envrc) with entries like this:

      # Local time for RCS date information
      RCSINIT "-zLT"
      # Default file browser.
      PAGER "less"

   A small perl script converts this into sh- or csh-style commands, so I
   can just source the appropriate file from .bashrc or .tcshrc or whatever:

      me% cat ~/.envrc.sh
      # Local time for RCS date information
      RCSINIT="-zLT"; export RCSINIT
      # Default file browser.
      PAGER="less"; export PAGER

      me% cat ~/.envrc.csh
      # Local time for RCS date information
      setenv RCSINIT "-zLT"
      # Default file browser.
      setenv PAGER "less"

   Aliases are annoying because the syntax is inconsistent, so I only use
   those for inside-the-shell stuff like job control.  Small ~/bin scripts
   handle things like using "dir" instead of "ls -lF":

      #!/bin/sh
      #<dir: long directory listing; skip colors if running script/saveon.
      case "$SAVEON" in
          "") opt='--color=auto' ;;
          *)  opt='' ;;
      esac
      unset BLOCK_SIZE    # throws off the results for GNU ls.
      exec /usr/local/bin/ls -lF $opt ${1+"$@"}
      exit 1

   Put the invariant stuff in the system startup files.  Something like
   this in /etc/profile would handle a general bash/ksh/sh environment:

      test -f "$HOME/.envrc.sh" && . $HOME/.envrc.sh

-- 
Karl Vogel                      I don't speak for the USAF or my company

If someone has a mid-life crisis while playing hide & seek,
does he automatically lose because he can't find himself?    --Steven Wright


More information about the freebsd-questions mailing list