December 1999
Beginner
528 pages
11h 10m
English
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.
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 ...Read now
Unlock full access