Functions in Bash
Posted by Dave Eddy on Sep 20 2010What is a function?
A function in Bash is like a function in any programming languages. A function is a subroutine in a program, and though I wont go into detail on that here you can learn more about it at wikipedia.
How to
In bash the syntax to create a function is really simple, here is an example.
function sayHello() { echo hello; }This creates a function called sayHello that, when called, will echo “hello” to the screen.
To call this function inside a script is also simple, you treat sayHello as though it is a
command that you would call just like any other in the script. For example:
#!/bin/bash
function sayHello() { echo hello; }
echo "about to call the function."
sayHello
echo "done"






