version 1.29, 2008/06/04 14:04:42 |
version 1.30, 2008/06/04 17:14:07 |
|
|
.El |
.El |
.Sh FUNCTIONS |
.Sh FUNCTIONS |
The awk language has a variety of built-in functions: |
The awk language has a variety of built-in functions: |
arithmetic, string, input/output and general. |
arithmetic, string, input/output, general, and bit-operation. |
|
.Pp |
|
Functions may be defined (at the position of a pattern-action statement) |
|
thusly: |
|
.Pp |
|
.Dl function foo(a, b, c) { ...; return x } |
|
.Pp |
|
Parameters are passed by value if scalar, and by reference if array name; |
|
functions may be called recursively. |
|
Parameters are local to the function; all other variables are global. |
|
Thus local variables may be created by providing excess parameters in |
|
the function definition. |
.Ss Arithmetic Functions |
.Ss Arithmetic Functions |
.Bl -tag -width "atan2(y, x)" |
.Bl -tag -width "atan2(y, x)" |
.It Fn atan2 y x |
.It Fn atan2 y x |
|
|
.Fa cmd |
.Fa cmd |
and returns its exit status. |
and returns its exit status. |
.El |
.El |
.Ss Bit-Operation functions |
.Ss Bit-Operation Functions |
.Bl -tag -width "lshift(a, b)" |
.Bl -tag -width "lshift(a, b)" |
.It Fn compl x |
.It Fn compl x |
Returns the bitwise complement of integer argument x. |
Returns the bitwise complement of integer argument x. |
.It Fn and x y |
.It Fn and x y |
Performs a bitwise AND on integer arguments x and y |
Performs a bitwise AND on integer arguments x and y. |
.It Fn or x y |
.It Fn or x y |
Performs a bitwise OR on integer arguments x and y |
Performs a bitwise OR on integer arguments x and y. |
.It Fn xor x y |
.It Fn xor x y |
Performs a bitwise Exclusive-OR on integer arguments x and y |
Performs a bitwise Exclusive-OR on integer arguments x and y. |
.It Fn lshift x n |
.It Fn lshift x n |
Returns x shifted by n bits to the left. |
Returns x shifted by n bits to the left. |
.It Fn rshift x n |
.It Fn rshift x n |
Returns y shifted by n bits to the right. |
Returns y shifted by n bits to the right. |
.El |
.El |
.Pp |
|
Functions may be defined (at the position of a pattern-action statement) |
|
thusly: |
|
.Pp |
|
.Dl function foo(a, b, c) { ...; return x } |
|
.Pp |
|
Parameters are passed by value if scalar, and by reference if array name; |
|
functions may be called recursively. |
|
Parameters are local to the function; all other variables are global. |
|
Thus local variables may be created by providing excess parameters in |
|
the function definition. |
|
.Sh EXAMPLES |
.Sh EXAMPLES |
Print lines longer than 72 characters: |
Print lines longer than 72 characters: |
.Pp |
.Pp |
|
|
.Op Fl \&dV |
.Op Fl \&dV |
and |
and |
.Op Fl safe , |
.Op Fl safe , |
as well as the command |
as well as the commands |
.Cm fflush , compl , and , or , xor , lshift , rshift |
.Cm fflush , compl , and , or , |
|
.Cm xor , lshift , rshift , |
are extensions to that specification. |
are extensions to that specification. |
.Sh HISTORY |
.Sh HISTORY |
An |
An |