The material in this recipe also appears in Learning the bash Shell by Cameron Newham (O'Reilly).
You have something that you'd like bash to do, but there's no built-in command for it. For efficiency reasons, you want it to be built-in to the shell rather than an external program. Or, you already have the code in C and don't want to or can't rewrite it.
Use the dynamically loadable built-ins introduced in bash version 2.0. The bash archive contains a number of pre-written built-ins in the directory ./examples/ loadables/, especially the canonical hello.c. You can build them by uncommenting the lines in the file Makefile that are relevant to your system, and typing make. We'll take one of these built-ins, tty, and use it as a case study for built-ins in general.
The following is a list of the built-ins provided in bash version 3.2's ./examples/
On systems that support dynamic loading, you can write your own built-ins in C, compile them into shared objects, and load them at any time from within the shell with the enable built-in.
We will discuss briefly how to go about writing a built-in and loading it in bash. The discussion assumes that you have experience with writing, compiling, ...