Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pacbell!pbhyf!rob From: rob@PacBell.COM (Rob Bernardo) Newsgroups: comp.bugs.sys5 Subject: Re: ksh bugs Keywords: ksh Message-ID: <5917@pbhyf.PacBell.COM> Date: 22 Aug 89 20:36:25 GMT References: <10166@fluke.COM> <10450@fluke.COM> <177@uci.UUCP> <1035@virtech.UUCP> <14571@bfmny0.UU.NET> <1170@vsi.COM> <14579@bfmny0.UUCP> Reply-To: rob@PacBell.COM (Rob Bernardo) Distribution: na Organization: Pacific * Bell, San Ramon, CA Lines: 41 In article <14579@bfmny0.UUCP> tneff@bfmny0.UU.NET (Tom Neff) writes: +In article <1170@vsi.COM> friedl@vsi.COM (Stephen J. Friedl) writes: +>In article <14571@bfmny0.UU.NET>, tneff@bfmny0.UU.NET (Tom Neff) writes: +> +>> export ENV='${Envfile[(_$-=1)+(_=0)-(_$-!=_${-%%*i*})]}' +> +>Hey, cool! I didn't know that ksh had a built-in APL interpreter! +> +>P.S. - or is that sed script? + +Actually it's a subscript expression, which evaluates to either $Envfile +or the null string depending on whether $- (the current flags) has an "i" +(for interactive) in it or not. Admittedly it looks like gobbledygook. +But it also shows how cute you can get in Korn shell. + +If I hadn't seen the expression my .profile would say + + case $- in + *i*) export ENV=$Envfile ;; + *) export ENV="" ;; + esac + +In fact it probably should anyway. :-) No you shouldn't have! :-) It wouldn't work. If you had that in your .profile, $- would *always* have an 'i' in it, and your ENV file would always be set to to $Envfile and never to the null string. One reason why the "gobbledygook" solution works is that two environmental variables ENV and PS1 are special in ksh insofar as they get evaluated when *used*! Notice that there are single quotes around the gobbledygook value that ENV is first set to. Therefore the value is not immediately evaluated (i.e. not evaluated when ENV is *set*). But it will be evaluated when ENV is *used*, namely when ksh is exec'd. So if the particular exec'd ksh is interactive, ENV will be set to $Envfile, if not interactive, it will be null. -- Rob Bernardo ...![backbone]!pacbell!pbhyf!rob -or- rob@pbhyf.PacBell.COM Product engineer, UNIX/C Reusable Code Library Editor, "Go `C' UNIX" Office: (415) 823-2417 Pacific * Bell, San Ramon, California Residence: (415) 827-4301 R BAR JB, Concord, California