...

/

Using Functions in Scripts

Using Functions in Scripts

Learn how to declare and call functions in scripts.

We'll cover the following...

We can declare a function in a script the same way as we do it in the shell. Bash allows both full or one-line form there. For example, let’s come back to the task of handling errors in the large program. We can declare the following function for printing error messages:

print_error()
{
  >&2 echo "The error has happened: $@"
}

This function expects input parameters. They should explain the root cause of the error to a user. Let’s suppose that ...