ENV file in ksh: is this smart? legal?

Chet Ramey chet at kiwi.CWRU.EDU
Sun Sep 3 05:07:56 AEST 1989


In article <716 at rodan.acs.syr.edu> Jerry Peek complains about ksh sourcing
the $ENV file for all invocations of shell scripts, interactive or not.

Doug Gwyn replies:

>That's a Korn shell design botch.  Apparently DGK thought that the C shell
>behavior should be mimicked.  Too bad he didn't first notice what a pain
>it already was for C shell users.  When Doug Kingston and I added a
>similar feature to the BRL Bourne shell, we were more careful, and I think
>ours works right.  It does NOT get sourced for shell scripts (unless they
>decide to source the file themselves, which would be exceedingly rare).

I think there might be an additional reason Korn did it that way: because
the Korn Shell does not provide exportable shell functions.  Using ksh, the
only way to have your personal shell functions (which are assumed to be
defined in the $ENV file) available when executing a script is to source
the $ENV file for every ksh invocation.  (The BRL Bourne Shell doesn't let
you export functions to a sub-shell either, so its users have the same
problem.)

You could argue that shell scripts that want or need these functions should
source the necessary files themselves (and I would agree with you), but
maybe Korn thought otherwise when he put the feature into ksh. 

(I can't resist a plug).  In BASH, the Gnu Bourne-Again SHell, functions are
exportable.  Version 1.03 was just released, grab it from prep.ai.mit.edu.

Chet Ramey (a bash contributor)
Chet Ramey			"We are preparing to think about contemplating 
Network Services Group, CWRU	 preliminary work on plans to develop a
chet at cwjcc.INS.CWRU.Edu		 schedule for producing the 10th Edition of 
				 the Unix Programmers Manual." -- Andrew Hume



More information about the Comp.unix.questions mailing list