LDP/LDP/guide/docbook/abs-guide/ex59.sh

39 lines
659 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2012-11-27 14:56:18 +00:00
# ex59.sh: Exercising functions (simple).
2001-07-10 14:25:50 +00:00
2004-01-26 00:03:37 +00:00
JUST_A_SECOND=1
2001-07-10 14:25:50 +00:00
funky ()
2004-01-26 00:03:37 +00:00
{ # This is about as simple as functions get.
2001-09-04 13:27:31 +00:00
echo "This is a funky function."
echo "Now exiting funky function."
} # Function declaration must precede call.
2001-07-10 14:25:50 +00:00
2004-01-26 00:03:37 +00:00
fun ()
{ # A somewhat more complex function.
i=0
REPEATS=30
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------------>"
2004-01-26 00:03:37 +00:00
echo
let "i+=1"
done
}
# Now, call the functions.
2001-07-10 14:25:50 +00:00
funky
2004-01-26 00:03:37 +00:00
fun
2001-07-10 14:25:50 +00:00
2012-11-27 14:56:18 +00:00
exit $?