ENV file in ksh: is this smart? legal?

Stephen Vinoski vinoski at apollo.HP.COM
Fri Sep 1 04:34:00 AEST 1989


In article <716 at rodan.acs.syr.edu> jdpeek at rodan.acs.syr.edu (Jerry Peek) writes:
>#2.  The next problem I have with ENV files -- if their name is stored
>in the environment (export ENV) -- is that Korn shell script files
>(shell programs) read them too.  I have some stuff in my ENV file that
>screws up shell scripts.
>
>Here's how I fixed the problem.  I put this at the start of my ENV file:
>	case "$-" in
>	*i*) ;;	# IF SHELL IS INTERACTIVE, READ THIS FILE
>	*) return ;; # ELSE, EXIT AND DON'T READ IT
>	esac

>From "The Kornshell Command and Programming Language" by Morris I. Bolsky and
David G. Korn, Prentice-Hall, 1989, ISBN 0-13-516972-0, page 78:

export FILE=$HOME/.envfile
# The subscript below evaluates to 0 when interactive.
ENV='${FILE[(_$-=0)+(_=1)-_${-%%*i*}]}'

This way ENV expands to null when the shell is not interactive.  I use this and
it works perfectly.

I also highly recommend the book - it's a great reference with some really good
examples of the power of the Kornshell.


-steve
-- 
# Steve Vinoski       # Apollo, a Subsidiary of HP  # ARPA: vinoski at apollo.com #
# (508)256-6600 x5904 # Chelmsford, MA  01824       # UUCP: ...!apollo!vinoski #
# "...no hardware designer should be allowed to produce any piece of hardware  #
#  until 3 software guys have signed off for it."   -Andy Tanenbaum            #



More information about the Comp.unix.questions mailing list