ksh bugs

Rob Bernardo rob at PacBell.COM
Wed Aug 23 06:36:25 AEST 1989


In article <14579 at bfmny0.UUCP> tneff at bfmny0.UU.NET (Tom Neff) writes:
+In article <1170 at vsi.COM> friedl at vsi.COM (Stephen J. Friedl) writes:
+>In article <14571 at bfmny0.UU.NET>, tneff at 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 at 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



More information about the Comp.bugs.sys5 mailing list