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 used $0, the shell would simply return a sh- message. The reason you get this message is because the file is not a script file. Either way this type of message is not very helpful to the user.
3.142.47.230