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.11. Calling functions

Let’s finish this chapter with two different ways of using functions: calling the functions from a source file and using functions that are already placed in your scripts.

19.11.1. Calling functions inside a script

To use a function in a script, create the function, and make sure it is above the code that calls it. Here’s a script that uses a couple of functions. We have seen the script before; it tests to see if a directory exists.

							$ pg direc_check !/bin/sh # function file is_it_a_directory() { # is_it_a_directory # to call: is_it_a_directory directory_name _DIRECTORY_NAME=$1 if [ $# -lt 1 ]; then echo "is_it_a_directory: I need a directory name to check" return 1 fi # is it a directory ? if [ ! -d $_DIRECTORY_NAME ...

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