O'Reilly logo

Linux and Unix Shell Programming by David Tansley

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

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.

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