() {
commands; }
Define name as a function. Syntax can be written on one line or across many. Since the Bourne shell has no aliasing capability, simple functions can serve as aliases. The Korn shell provides the function
keyword, an alternate form that works the same way.
There are semantic differences that should be kept in mind:
In the Bourne shell, all functions share traps with the "parent" shell and may not be recursive.
In ksh88, all functions have their own traps and local variables, and may be recursive.
In ksh93, name ()
functions share traps with the "parent" shell and may not be recursive.
In ksh93, function
functions have their own traps and local variables, and may be recursive. Using the .
command with a function
function gives it Bourne shell semantics.
$count () {
>ls | wc -l
>}
When issued at the command line, count
now displays the number of files in the current directory.