Functions

Functions are a much better way of defining your own commands for use on the Bash command line, and in Bash scripts. They can do everything aliases can, and more.

Well, almost everything. There are some niche tricks you can do with aliases and not functions alone, but they are essentially clever hacks and mostly a curiosity. Take a look at Simon Tatham's Magic Aliases article to learn more: https://www.chiark.greenend.org.uk/~sgtatham/aliases.html.

A great deal of what we discuss for functions will be applicable to the next section on scripts. There are some important differences in the way the two work, but they have a lot in common. We will highlight the similarities in the next section.

Get Bash Quick Start Guide 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.