December 1999
Beginner
528 pages
11h 10m
English
Let’s create a function file that holds one function. We will load it into the shell, test it, make a change then reload it.
Create a file called functions.main and type in the following:
$ pg functions.main
#!/bin/sh
# functions.main
#
# findit: this is front end for the basic find command
findit() {
# findit
if [ $# -lt 1 ]; then
echo "usage :findit file"
return 1
fi
find / -name $1 -print The above is a script used previously in the book, but now it has been turned into a function. It’s a front end to a basic find command. If no argument is passed to it, a return with a value of 1 is executed meaning errors have occurred. Notice on the error statement that the actual function name is shown, because if we had ...
Read now
Unlock full access