Name

function

Synopsis

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

Define name as a shell function. See the description of semantic issues in the earlier section "Functions.” The first form is for the Korn shell, although it may also be used with Bash. The second form is specific to Bash. Bash does not give different semantics to functions declared differently; all Bash functions behave the same way.

Example

Define a function to count files.

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

Get Unix in a Nutshell, 4th 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.