Calling subroutine in Bash (bash sub / function / routine)

in bash shell it is something like this....

function function-name {
shell commands...
}

or just

function-name () {
shell commands...
}

#!/bin/bash

test ()
{
echo Hey I am here.
echo Now exiting function.
}

# Note: function must precede call.

# Now, call the function.

test

exit 0
------------------------------
here is another one which process passing arguments...

#!/bin/bash

func2() {
if [ -z $1 ]
# Checks if any params.
then
echo "No parameters passed to function."
return 0
else
echo "Param #1 is $1."
fi

if [ $2 ]
then
echo "Parameter #2 is $2."
fi
}

func2
# Called with no params
echo

func2 first
# Called with one param
echo

func2 first second
# Called with two params
echo

exit 0
----------------------

another important thing used in functions is return statement, which
optionally takes an integer argument, which is returned to the calling
script as the "exit status" of the function, and this exit status is
assigned to the variable $?