Go to the previous, next section.

þ

Functions

þ

The function reserved word is used to define shell functions. Shell functions are read in and stored internally. Alias names are resolved when the function is read. Functions are executed like commands with the arguments passed as positional parameters.

Functions execute in the same process as the caller and share all files and the present working directory with the caller. A trap on EXIT set inside a function is executed after the function completes in the environment of the caller.þ

The return builtin is used to return from function calls. þ þ

Function identifiers can be listed with the functions builtin. Functions can be undefined with the unfunction builtin.

The following functions, if defined, have special meaning to the shell:

þ

chpwd
Executed whenever the current working directory is changed. þ

precmd
Executed before each prompt. þ þ

periodic
If the parameter PERIOD is set, this function is executed every PERIOD seconds, just before a prompt.þ þ þ þ þ

TRAPxxx
If defined and non-null, this function will be executed whenever the shell catches a signal SIGxxx, where xxx is a signal name as specified for the kill builtin (see section Shell Builtin Commands). In addition, TRAPZERR is executed whenever a command has a non-zero exit status, TRAPDEBUG is executed after each command, and TRAPEXIT is executed when the shell exits, or when the current function exits if defined inside a function. If a function of this form is defined and null, the shell and processes spawned by it will ignore SIGxxx.

Go to the previous, next section.