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

Chapter 19. Shell functions

All the code in the scripts so far in this book has been executed from top to bottom. This approach is OK, but you may have noticed that some segments of the code we have covered in our examples has been duplicated further on in the same script.

The shell allows you to group a set of commands or statements into a reusable block. These blocks are called shell functions.

In this chapter we will cover:

  • defining functions;

  • using functions from within a script;

  • using functions from a functions file; and

  • function examples.

A function is made up of two parts:

The function label The function body 

The label is the function name and the body is the set of commands inside the function. The label name should really be unique; if ...

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