Hour 14. Functions

Shell functions provide a way of mapping a name to a list of commands. Functions are similar to subroutines and procedures in other programming languages. You can also think of them as miniature shell scripts, complete with exit codes and arguments. The main difference between a script and a function is that a new instance of the shell is started for a shell script, whereas functions run in the current instance of the shell.

This chapter is divided into the following two sections:

The first section introduces the syntax for defining functions and illustrates their use, whereas the second section covers more advanced topics relating to the interaction ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition 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.