home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / shell / 5105 < prev    next >
Encoding:
Text File  |  1992-12-20  |  3.3 KB  |  73 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!s5!is1.is.morgan.com!is0.is.morgan.com!wpm
  3. From: wpm@is.morgan.com (W. Phillip Moore)
  4. Subject: ksh autoload quirk
  5. In-Reply-To: dattier@ddsw1.mcs.com's message of Wed, 16 Dec 1992 20:01:49 GMT
  6. Message-ID: <WPM.92Dec18103702@exile.is.morgan.com>
  7. Sender: news@is.morgan.com
  8. Nntp-Posting-Host: exile
  9. Organization: Informations Services Dept., Morgan Stanley Japan
  10. References: <BzDBn2.KAw@ddsw1.mcs.com>
  11. Date: Fri, 18 Dec 1992 15:37:02 GMT
  12. Lines: 59
  13.  
  14.  
  15. >>>>> "David" == DWT  <dattier@ddsw1.mcs.com>:
  16.  
  17. David> ksh 11/16/88d under Dell SVR4 4.0 here on ddsw1 and the ksh running
  18. David> on a 3B2 on gagme recognize any filename in a directory in $FPATH as
  19. David> an undefined function whether or not that name has been declared for
  20. David> autoload with "autoload" or "typeset -fu."
  21.  
  22. I see the same behavior for the same version running on SunOS -- this
  23. behavior is a feature/bug.
  24.  
  25. David> But there is a difference when a file in $FPATH has the same name as
  26. David> an executable file in $PATH.  If the undefined function has been
  27. David> formally declared with "autoload" or "typeset -fu," then ksh
  28. David> interprets an appearance of that name on the command line as a
  29. David> reference to the function.  If the undefined function has not been
  30. David> declared but is recognized as such solely by dint of lying in
  31. David> $FPATH, then an appearance of the name on the command line is taken
  32. David> by ksh parser to mean the executable in $PATH (unless the function
  33. David> has actually been loaded with the . command or by a call to another
  34. David> function in the same file to whose name the file is linked).
  35.  
  36. I verified the same by tracing some scripts I wrote.  This is really
  37. frustrating, because I would like to provide a set of utilities to our
  38. users and make them available simple by exporting FPATH in out default
  39. environment.  There is a noticable performance penalty if one does not
  40. autoload, linearly dependent on the size of PATH, in addition to not being
  41. able to provide simple wrappers to system commands.
  42.  
  43. Furthermore, subshells inherit FPATH, but do NOT inherit functions
  44. definitions.  The shell which does all the autoloading will work as
  45. expected, but subshells will not.
  46.  
  47. An ugly workaround is to do the following in the $ENV file:
  48.  
  49. for DIR in $( echo $FPATH | sed -e 's/:/ /g' ) ; do
  50.   for FILE in $DIR/* ; do
  51.     [[ -f $FILE && -x $FILE ]] && autoload ${FILE##*/}
  52.   done
  53. done
  54.  
  55. David> Is that the correct behavior?  Is a file name in $FPATH that hasn't
  56. David> been declared for autoload supposed to be recognizable at all as an
  57. David> undefined function?  I haven't seen anything about that (nor about a
  58. David> difference in precedence from a declared undefined function) in the
  59. David> ferkakte manual.
  60.  
  61. If by the manual you are refering to "The Kornshell" by Bolsky and Korn,
  62. then I have also searched this in vain for documentation on the above
  63. behavior.  I'm about ready to plow through the source, and maybe fix this.
  64.  
  65. Id there any reason NOT to simply search and autoload anything in FPATH
  66. before earching PATH??  I assume there was a reason for coding ksh this
  67. way.
  68.  
  69. W. Phillip Moore                                        Phone: 81-3-3286-9359
  70. Information Services Department                           FAX: 81-3-3286-9040
  71. Morgan Stanley Japan Ltd.  Tokyo Branch             E-mail: wpm@is.morgan.com
  72.         Ote Center Bldg. 3F, 1-1-3 Otemachi, Chiyoda-ku, Tokyo 100
  73.