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.7. Creating a function file

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

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