shell function

A named group of commands, defined as name() { ...; }, that you then run like any other command.

In more detail

A function runs in the current shell, so it can change variables and the current directory, and it receives its own $1, $2 and $@. Variables set inside are global unless declared local. Functions replace aliases in scripts and let a long script read as a series of named steps.

Examples

greet() { echo "hello, $1"; }
greet ada

Related terms

Taught in

References