19.4. Returning from a called function

When a function has finished processing or you wish the function to finish based on a conditional statement, you can do one of two things:

  1. Let the function fall through naturally to the end of the function, thus returning control back to the part of the script that called it.

  2. Use the word ‘return’, which will return from the function to the next statement of your script from whence it was called. A value can be used with the return; this is optional, and is 0 for non-errors and 1 for errors, pretty much the same as the last status command reports. The format is:

    return will return from the function, use the last status command to determine status
    return 0 for non-errors
    return 1 for errors

Get Linux and Unix Shell Programming 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.