return

The [[builtin?]] '''return''' [[command?]], can be used to exit from a [[function?]] within the awk script, returning control to the calling section.

The return [[command?]] takes the form of:

return foo

Where foo is an [[expression?]] that evaluates to a [[return_value?]] that is to be made available to the calling section.

Using the return value command to set an errorlevel

By convention, when a function exits normally it should give a [[return_value?]] of zero:

return 0 # Function completed normal operation without an error

It is possible to set an [[errorlevel?]] using the return command, which can be utilized by the calling section:

return 245 # Function gave an internal error

Omitting the return value

In awk, if no [[return_value?]] is specified, then an [[unspecified?]] value will be produced. A calling section should not make any evaluation based on the [[return_value?]] of a [[function?]] that returns an [[unspecified?]] value.

A function with no explicit return will produce an unspecified value

If the end of a [[function?]] block is reached and no explicit return [[command?]] has been given, then the [[function?]] will return an [[unspecified?]] value.