*BSD News Article 84124


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!news.idt.net!cam-news-hub1.bbnplanet.com!news.bbnplanet.com!cpk-news-hub1.bbnplanet.com!newsfeed.internetmci.com!news.wwa.com!chilton!chris
From: chris@vindaloo.com (Christopher Sean Hilton)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Serious brain damage in /bin/sh for FreeBSD 2.1.5
Date: Tue, 3 Dec 1996 03:12:50 GMT
Organization: Vindaloo Communications
Lines: 97
Message-ID: <E1tI9E.GM8@vindaloo.com>
References: <stanbE1M2D2.38I@netcom.com> <stanbE1Mw49.41q@netcom.com> <57p5ad$jmv@ns.qnis.net> <stanbE1puHB.E20@netcom.com>
NNTP-Posting-Host: pool19-000.wwa.com

In article <stanbE1puHB.E20@netcom.com>, Stan Brown <stanb@netcom.com> wrote:
>phil@ns.qnis.net (Phil Jensen) writes:

[snip]

I'm hacking out the part about whether or not /bin/sh should dot in the
$ENV variable if it finds it. I'm not qualified to comment on this
since I haven't read posix. 

>	Now show me how to make this $ENV file smart enough to not break *all*
>	system functions implemented as a /bin/sh script.
>
>	Here are thisng that *won't* work.
>
>	1. checking $SHELL (/bin/sh doesn't change the value of this).
>
>	2. checking $0 (this won't work since this will be the scripts name
>	   not /bin/sh).
>
>	3. unseting $ENV at the end of the $ENV file.
>

This construct works on my machine:

#---------------------------------------------------------------------
# Module:	kshrc
# Author:	Christopher Sean Hilton
# Date:		19 May, 1996
#---------------------------------------------------------------------
# Korn Shell autosetup script. If the environment variable ENV points
# to this script it will be executed at the start of all Korn shell
# scripts. Unfortunatly newer Bourne shells do the same thing but
# without the richer command set of the Korn Shell. This can lead to
# problems for both interactive and non-interactive shells so a lot of
# the work is farmed out to sub command scripts and then included via
# the '.' inclusion command which is common to both shells. This helps
# out because the shell can interpret these commands even if it's not
# going to execute them.
# 

#---------------------------------------------------------------------
# Find out if this is the Korn shell. If it is then move on. If there
# was a similar initialization sequence for the Bourne shell it should
# have to be coded in this program. If that were the case it would
# probably be a good idea to rename this.

if [ ! -z "$KSH_VERSION" ]
then

	#
        # Korn shell syntax ([[ etc ) is okay here.
        #

fi

This is what I use in my kshrc script to change my prompt or the title
on an xterm/rxvt window to reflect the directory I'm in. Take not of a
couple of things here... 

First you cannot use the Korn shell [[ in place of the Bourne shell [
in your test because this line will be evaluated by both shells. 

Second: This file should really only contain Bourne shell
constructs. For some reason that I confess that I don't understand
fully the FreeBSD Bourne shell is not a true interpreter and actually
tries to translate the commands in the then side of the if loop even
though it's not going to execute them. If you need to do Korn shell
stuff within this file you can do something like this however...

----- Doesn't work -----

if [ ! -z "$KSH_VERSION" ]
then
	progname=${0%%*/}
fi

----- Works -----

if [ ! -z "$KSH_VERSION" ]
then
	. ksh_script
fi

where the ksh_script uses Korn shell only constructs.

I noticed that you have an earlier thread here about getting xterms
and rxvts to change their prompts. If you like I can show you how I
solved this problem. Feel free to e-mail me at <chris@vindaloo.com>

Chris


-- 
+--------------------------------------------------------------------+
|    __o         "All I was doing was trying to get home from work." |
|  _`\<,_         -Rosa Parks                                        |
+_(*)/_(*)___________________________________________________________+