Shell Functions
Shell functions are very similar to functions in most programming languages. They allow us to group commands into a unit and provide them with a name. We can later execute the commands in the function by invoking its name, just like any other command. In essence, shell functions let us define our own commands that are indistinguishable from the inbuilt ones.
Function Definition
Functions can be created with this basic syntax:
function name() { Â Â COMMANDS }
Here, COMMANDS
may be one or more commands, lists, or pipelines, and represent the function body. The braces must be separated from the rest of the syntax with whitespace, typically with newlines. When the function name is typed on the command line as if it were a command, we say that the function has been invoked or called and the commands in the function body are executed.
Note
The function
keyword can be omitted when defining a function—it is optional, according to the syntax...