Functions

Functions are basically groups of statements that can be called with a single command. They can almost be thought of as “mini-programs inside programs.” Using functions in your shell programs can make your life a lot easier—for two reasons. First of all, if you need to perform the operation in multiple places in your program, you can simply type the name of the function rather than having to retype all the code each time you need to perform the operation. Second, if you later decide you need to make the operation work differently, you only have to change the function rather than go through the code and change it every place it is used. The following shows a simple example of a function that cleans up temp files, and so on, after a shell ...

Get FreeBSD® Unleashed 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.