Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-sdd!apollo!vinoski From: vinoski@apollo.HP.COM (Stephen Vinoski) Newsgroups: comp.unix.questions Subject: Re: ENV file in ksh: is this smart? legal? Keywords: ksh, ENV Message-ID: <455cc299.13868@apollo.HP.COM> Date: 31 Aug 89 18:34:00 GMT References: <716@rodan.acs.syr.edu> Reply-To: vinoski@zep.UUCP (Stephen Vinoski) Organization: Hewlett-Packard Apollo Division, Chelmsford, MA Lines: 32 In article <716@rodan.acs.syr.edu> jdpeek@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@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 #