Name

function

Synopsis

[function] name (  ) { commands; }
function name { commands; }

Define name as a shell function. See the description of semantic issues in the section Functions in Functions. If the reserved word function is given, the parentheses following name are optional.

Example

Define a function to count files:

$ function fcount {
    >    ls | wc -l
    >}

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.