Monday, June 2, 2008

Functions in Shell-Scripting => Part 1

#!/bin/bash
#Author: Parag Kalra
#Date: 3rd June, 2008
#Name: func1.sh
#Usage: ./func1.sh
#Purpose: To illustrate usage of functions in Shell Scripts.

JUST_A_SECOND=1
REPEATS=3

funky()
{
echo "This is a just funky function...not that exciting..."
}

fun()
{
echo "The real fun starts now."
i=0
sleep $JUST_A_SECOND

while [ $i -lt $REPEATS ]
do
echo "FUNCTIONS R FUN"
echo
let "i+=1"
done
}

funky
fun

The output of above script is:

This is a just funky function...not that exciting...
The real fun starts now.
FUNCTIONS R FUN

FUNCTIONS R FUN

FUNCTIONS R FUN


Just go through it and let me know if you happen to come across any bug in it. eMail me at paragkalra@gmail.com

No comments: