Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!udel!burdvax!bpa!cbmvax!vu-vlsi!cgh!manta!brant From: brant@manta.UUCP (Brant Cheikes) Newsgroups: comp.sys.att Subject: Curious ksh hack Message-ID: <340@manta.UUCP> Date: 8 Mar 88 03:21:35 GMT Reply-To: brant@manta.UUCP (Brant Cheikes) Organization: Soul of the Gnu Machine, Philadelphia Lines: 43 In a memo by David Korn describing ksh, there is a paragraph that states: "The ENV file can have an undesirable effect on performance. Even if this file is small, the shell must perform an open of this file. If large functions are placed in the ENV file they must be read in and compiled even if they are never referenced. If you only need the startup file for interactive shells, then set your ENV variable to a value which evaluates to a file name for interactive shells and to the null string otherwise. If you export the startup file name in the variable START, then setting ENV='${START[(_$-=1)+(_=0)-(_$-!=_{-%%*i*})]}' will only invoke the startup file for interactive shells since the subscript evaluates to 0 only if the shell is interactive." Now, I've done this and it works, but I can't quite figure out how. I've figured out the following: 1. $- evaluates to the shell args, for an interactive shell this is something like 'is', otherwise just 's'. 2. _$-=1 evaluates to _=1, e.g., _is=1 3. _=0 is just _=0 4. _$-!=_{-%%*i*} becomes _is!=_ (if shell args contains 'i') and _s!=_s otherwise. So for an interactive shell, we get (_is=1)+(_=0)-(_is!=_) At this point I'm lost. Don't the parenthesized items invoke subshells? How does this turn out to be 0? And how does it turn out to be 1 if the shell is non-interactive? Can anyone shed some light on how this little hack works? At least this little trick should be of general interest, since it's only documented in the internal ksh memo, not any of the manuals I've been able to find. -- Brant Cheikes University of Pennsylvania Department of Computer and Information Science ARPA: brant@linc.cis.upenn.edu, UUCP: ...drexel!manta!brant