How to use functions in BASH

Home > Search > How-to
  by

Functions in BASH are similar to functions in other programming languages. The function contains a segment of markup. In this example, the name of the function is execution, and then function is used simply by having a line with the word execution.

function execution {
  a bunch of markup here
}

execution

 

It is somewhat common to have an execution function and a debugging function. The debugging function would contain markup that is used to debug the script. The debugging fuction would be used to debug the script. Typically, the debugging function will be commented out. This way, when something goes wrong, you simply just uncomment debugging, and used the output of the debugging funtion to debug the script.

function execution {
  a bunch of execution markup here
}

function debugging {
  a bunch of debugging markup here
}

execution
#debugging

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments