SUMMARY: Exporting functions in Korn shell.

From: Matthew Calthrop +44 (0) 171 542 5317 <"Matthew>
Date: Mon, 27 Jan 1997 12:01:40 +0000 (GMT)

My original posting:

=It seems impossible to export a function so that it is inherited by a
=new invocation of the Korn shell, despite what the manual page says.
=
=I have tried everything I could think of, including using "typeset
=-xf", and I can't get it to work.
=
=Can anyone help me on this one?
=Is this a "known bug"?
=Is there another version of the Korn shell which actually does this?

The solution was quite simple and neat, if poorly (un?) documented.

1. In /etc/profile (or a user's .profile, as required) define the
environment variable FPATH to point to a directory in which functions
will exist, eg export FPATH=/usr/local/functions. You can treat this
env. variable like the PATH variable, and append other directories,
separated by a colon.

2. For each function required, create a file in one of the directories
in $FPATH. The name of the file will be the name of the function, and
the file will contain the function definition as well. Eg, contents of
/usr/local/functions/dir:

#!/bin/ksh
# do a long listing, piped to $PAGER
dir() {
    /bin/ls -lAF $* | $PAGER
}

The function will not be loaded into memory until called:
mjc_at_knowledge> type dir
dir is an undefined function
mjc_at_knowledge> dir /tmp
total 1426
drwxrwxrwt 2 root 8192 Jan 23 10:12 .X11-unix/
drwx------ 2 root 8192 Dec 19 12:53 .tags/
...blah...
mjc_at_knowledge> type dir
dir is a function
mjc_at_knowledge>


Thanks to Steve Beikman (beikman_at_xtdl.com) for his help.

regards,

Matt
matthew.calthrop_at_reuters.com
Received on Mon Jan 27 1997 - 13:19:38 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:47 NZDT