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 ...

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.