User defined functions
Typically bash functions are permanently stored in a
bash start-up script.
- System-wide start-up scripts:
/etc/profile for login shells, and
/etc/bashrc for interactive shells.
- User define start-up scripts:
~/.bash_profile for login shells, and
~/.bashrc for interactive shells.
- More information on interactive/login shells can be found in the bash
man page in the INVOCATION section.
User defined shell functions are loaded dynamically in a hash (or lookup table) when bash starts. From the bash source file
variable.c the definition for the table is:
/* The list of shell functions that the user has created, or that came from
the environment. */
HASH_TABLE *shell_functions = (HASH_TABLE *)NULL;
User defined functions can be listed with the bash
declare command, other shells still use
typeset. In bash
declare has superceded the
The functions exist in memory for the lifetime of the bash shell.
Shell defined (builtin) functions
These are common functions such as
:. They are compiled into a library which is linked into the
bash executable. Building the definitions into the executable saves time compared to loading an external definition. Definitions for these functions (held in
.def source files which are parsed into C source) are held in the
builtins directory of bash source.
A useful aside: for information on a shell builtin command use
help # list all builtins
help declare # info and options for declare
help -m declare # gives man style information for declare