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