O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Return statement

The body of the user-defined function can also contain a return statement, similar to return statements found in other programming languages. The statement returns control to the calling part of the AWK program. Its syntax is as follows:

return [ expression ]

In the following example, the func_add(), func_sub(), and func_mul() functions return the addition, subtraction, and multiplication of the numbers passed as arguments to them:

$ vi func3.awkfunction find_add(num1, num2){    result = num1 + num2    return result}function find_sub(num1, num2){    result = num1 - num2    return result}function find_mul(num1, num2){    result = num1 * num2    return result}# Main functionfunction main(){    printf "Enter first number : "  getline num1 < "-" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required