bash functions

Updated: 25 January 2025

Taken from Advanced Bash-Scripting Guide: functions

#!/bin/bash

JUST_A_SECOND=1

funky () { echo "Call to funky"; echo "Exiting funky"; }

fun ()
{
  i=0
  REPEATS=4

  echo
  echo "And now the fun really begins."
  echo

  sleep $JUST_A_SECOND    # Hey, wait a second!
  while [ $i -lt $REPEATS ]
  do
    echo "<----------FUNCTIONS---------->"
    echo "<------------ARE-------------->"
    echo "<------------FUN-------------->"
    echo
    let "i+=1"
  done
}

funky
fun

# Exit with status of the last executed command.
exit $?

Leave a comment