December 1999
Beginner
528 pages
11h 10m
English
Now we have created a function let’s see it being used in a script.
$ pg func1
#!/bin/sh
# func1
hello ()
{
echo "Hello there today’s date is `date`"
}
echo "now going to the function hello"
hello
echo "back from the function" When the above script is run, we get:
$ func1
now going to the function hello
Hello there today’s date is Sun Jun 6 10:46:59 GMT 1999
back from the function
In the above example, the function is declared at the top of the script. To reference the function we called it by its name which was ‘hello’. When the function has finished, control returns to the next statement following the function call, which is the echo statement ‘back from the function’.
Read now
Unlock full access