Bourne | Ash |  #!  | find | ARG_MAX | Shells | portability | permissions | UUOC | ancient | - | ../Various | HOME
"$@" | echo/printf | set -e | test | tty defs | tty chars | $() vs ) | IFS | using siginfo | nanosleep | line charset | locale


PATH search for functions

There is a characteristic feature of almquist shells in general. It's one of probably only two common characteristic feature of all almquist shell variants, although it's not documented anymore since 4.4BSD-Alpha.

A path component flagged with a trailing "%func" is recognized as a directory containing function definitions
(and "%builtin" is the counterpart to let a built-in override a function again).
Here is a link to the respective manual page section and in DIFFERENCES read item 6 and 7.

Here is an example:

    $ cat myfunction
    myfunction()  { echo in myfunction; }
    $ PATH=$PATH:.%func
    $ myfunction
    in myfunction
The shell searches for a file with the requested name, reads it and executes a function with the requested name if available.
It reads the whole file, so you can use a single file with several definitions with the respective hardlinks to it.
In fact, as a side effect, other definitions, like variable assignments, remain in effect as well.

The file is only read once, because the definitions are hashed. However, the hash built-in doesn't report functions.
Also, unlike some other shells, Almquist shells don't report function definitions with the set built-in, so there's no way to know the hashed definitions.

The manual page was completely rewritten for 4.4BSD-alpha. Since then, the feature is not documented anymore.
But the code remained untouched in all descendants listed on these pages, even in the minimalistic busybox variant.