19.1. Declaring functions in a script

Here is a simple function:

hello () {echo "Hello there today’s date is `date`" } 

All functions have to be declared before you use them. What this means is that you must put all your functions at the top of the script. You cannot reference a function until the shell interpreter has seen it first. To call a function you simply call it by its name. In the above example, the function name is ‘hello’; the function’s body contains a echo statement containing today’s date.

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.