Any good programming language provides support for functions. A function is a bundle of statements that is executed as a group. The bundles are executed just like a “regular” command and are used to carry out often-required tasks. An advantage of a function is that it is held in the computer’s main memory, so execution is much quicker than with a script, which must be retrieved from disk. The current version of the Bourne shell supports shell functions; older versions of the Bourne shell did not. The syntax for shell functions is as follows:
name() { command-list }
This command syntax defines a function named name. The body of the function is the command-list between { and }. This list is executed whenever name is specified as the name of a command. As an example, at the command prompt, type the following:
hello() { echo hello there }
The function is named hello and can be executed by typing hello. The output of the function is hello there. The exit status of a function is the exit status of the last command executed in the body.