Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!ukc!its63b!simon From: simon@its63b.ed.ac.uk (ECSC68 S Brown CS) Newsgroups: comp.unix.questions Subject: Re: Korn Shell Message-ID: <339@its63b.ed.ac.uk> Date: Thu, 19-Mar-87 05:09:43 EST Article-I.D.: its63b.339 Posted: Thu Mar 19 05:09:43 1987 Date-Received: Sat, 21-Mar-87 08:53:40 EST References: <580@csun.UUCP> <5680@brl-smoke.ARPA> <2201@ptsfa.UUCP> <730@hoqax.UUCP> <2204@ptsfa.UUCP> Reply-To: simon@its63b.ed.ac.uk (ECSC68 S Brown CS) Organization: I.T. School, Univ. of Edinburgh, U.K. Lines: 48 Keywords: Korn shell ksh aliases parameters In article <2204@ptsfa.UUCP> dsp@ptsfa.UUCP (David St.Pierre) writes: >In article <730@hoqax.UUCP> twb@hoqax.UUCP (BEATTIE) writes: >> >>Since this is in the ENV file doesn't it significantly increase the >>amount of time it takes to start a sub-shell. > >Doesn't really seem to. It may not have been apparent, but the dirs, popd, ... >functions were actually defined in a separate file. An alias was defined >which sourced then in at first reference and unaliased them. You bite it >big the first time you use the functions, but after that it's pretty fast. > In a version of the shell I've been hacking around, I've introduced a new keyword - "extern" - which defines an alias (or shell-function, or whatever) as existing in a library-file, but without explicitly giving it a value. When it is executed, it is recognized as being external and is automatically loaded in from the library file before executing it. So, the definition takes hardly any time at all (less characters to read, no parsing necessary), the first reference takes a while (search through a library file to find it - though hashed indexing could speed it up for very large libraries), and subsequent references can use the previously loaded-in alias value with no overhead at all at all. For example, "extern suspend" means that "suspend" is an external function (which implements job-control shell-suspension under systemV). (In fact, "extern -a" declares all the functions in a standard shell-library). This method allows lots of builtins to be taken out of the shell itself (if they were only there for efficiency reasons), and implemented as external functions instead. >> >>Why can't aliases and functions be exported like shell variables? > I do this by creating a variable called "ENV_FUNCTIONS" (or something like that) which has as its value a list of all functions that have been exported. Functions are exported with "export -f ". (Just "export -f" causes *all* functions to be exported). When a subshell starts up, it defines all the functions listed in this variable. For example, ENV_FUNCTIONS="extern suspend; extern pwd; hello(){ echo hi; }; ..." -- ---------------------------------- | Simon Brown | UUCP: seismo!mcvax!ukc!{its63b,cstvax}!simon | Department of Computer Science | JANET: simon@uk.ac.ed.{its63b,cstvax} | University of Edinburgh, | ARPA: simon%{its63b,cstvax}.ed.ac.uk\ | Scotland, UK. | @cs.ucl.ac.uk ---------------------------------- "Life's like that, you know"