Subject: Re: ksh [was: Re: miniroot for NetBSD/i386?]
To: Simon J. Gerraty <sjg@crufty.net>
From: Igor Sobrado <igor@string1.ciencias.uniovi.es>
List: port-i386
Date: 03/19/2006 12:47:02
In message <20060318020257.2ECD6A3E9@zen.crufty.net>, Simon J. Gerraty writes:
> >> IIRC this only works if you do NOT have the VISUAL env var set.
> >> Kinda strange...
> 
> >$ set -o emacs
> >$ VISUAL=vi; export VISUAL
> 
> The trick is to
> 
> export VISUAL=vi
> 
> in ~/.profile and
> 
> set -o emacs
> 
> in $ENV (eg ~/.kshrc)

Hi, Simon.

Nice to see that this thread is alive yet.  ;-)

The way EDITOR and VISUAL environment variables are interacting is
something dark, as shown by Hubert Feyrer in that thread.  By default,
both the shell and editor behaviour are the same----in other words,
if VISUAL is not set, EDITOR will set VISUAL to a value that match
the chosed editor.  If VISUAL is set, EDITOR will not change its
current value.  Setting up a personal configuration file using ENV
is certainly useful; in this case, it preserves the order in which
changes must be made.

> I've used pdksh and various other ksh for many years, though I avoid writing 
> scripts that need more than /bin/sh (though on some boxes ksh is the _only_
> sane shell), I very rarely notice a difference b/w pdksh and ksh on 
> Solaris or HP-UX (though I've not used that for a few years now).
> 
> If interested http://www.crufty.net/ftp/pub/unix/configs/etc/ has copies
> of a decent? /etc/profile and ksh.* which I've used on lots of flavours
> of unix.

In my humble opinion, these configuration files are too complex and
too large.  These files can be exported from a centralized filesystem
(e.g., by NFS) to a large number of clients running different Unix
and BSD flavours.  On the wrong side, these files are difficult to
maintain and, probably, a bit slow when users log in to the system.

I like this approach, even if we need to maintain different
configuration files for each OS flavour:


#
# This is the default .profile file.
# Users are expected to edit it to meet their own needs.
#
# The commands in this file are executed when an sh user first
# logs in.
#
# See sh(1) for details.
#
# $Id: dot.profile,v 1.9.4.17 2005/08/16 10:47:15 sobrado Exp $
#

umask 022
PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
PATH=${PATH}:/usr/pkg/bin:/usr/pkg/sbin:/usr/games
export PATH

case $- in
*i*)	# do things for interactive shell
	eval `tset -Qs -m 'network:?xterm'`
	stty status '^T' crt -tostop
	set -o emacs
	;;
*)	# do things for non-interactive shell
	;;
esac
trap "find $HOME/tmp -type f -atime +7 -exec rm -f -- {} \;" 0


(I read about the case structure shown in this file on the Unix FAQ,
section 5.5, a lot of years ago and used it since then.)

Of course, you can maintain "local configuration files" for each
architecture setting ENV (in ksh) to something like this one:

  ENV=".kshrc."`uname`; export ENV

and setting up local files as ".kshrc.NetBSD" with local commands
for each OS architecture.  I like using "export" in this way instead
of "export VAR=<value>" as Bourne (not Korn) shells usually do
not understand the second structure and I want a portable
~/.profile file.

I certainly would suggest upgrading the default Bourne shell
configuration file in NetBSD to support this case structure.
I really found it useful and increases performance when running
non-interactive shells.

Best wishes,

Igor.