Chapter 12: Using Arguments and Functions

Whenever we are trying to program any kind of application or a script in any programming language, we should always try to make our code modular and easily maintainable. The thing that is going to help us a lot in this aspect of creating scripts is a concept known as a function.

We will cover the following recipes in this chapter:

  • Using custom functions in shell script code
  • Passing arguments to a function
  • Local and global variables
  • Working with returns from a function
  • Loading an external function to a shell script
  • Implementing commonly used procedures via functions

Technical requirements

For these recipes, we're going to use a Linux machine. We can use any virtual machine (VM) from our previous ...

Get Linux Command Line and Shell Scripting Techniques 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.