| 1 | #!/bin/bash |
| 2 | # ex59.sh: Exercising functions (simple). |
| 3 | |
| 4 | JUST_A_SECOND=1 |
| 5 | |
| 6 | funky () |
| 7 | { # This is about as simple as functions get. |
| 8 | echo "This is a funky function." |
| 9 | echo "Now exiting funky function." |
| 10 | } # Function declaration must precede call. |
| 11 | |
| 12 | |
| 13 | fun () |
| 14 | { # A somewhat more complex function. |
| 15 | i=0 |
| 16 | REPEATS=30 |
| 17 | |
| 18 | echo |
| 19 | echo "And now the fun really begins." |
| 20 | echo |
| 21 | |
| 22 | sleep $JUST_A_SECOND # Hey, wait a second! |
| 23 | while [ $i -lt $REPEATS ] |
| 24 | do |
| 25 | echo "----------FUNCTIONS---------->" |
| 26 | echo "<------------ARE-------------" |
| 27 | echo "<------------FUN------------>" |
| 28 | echo |
| 29 | let "i+=1" |
| 30 | done |
| 31 | } |
| 32 | |
| 33 | # Now, call the functions. |
| 34 | |
| 35 | funky |
| 36 | fun |
| 37 | |
| 38 | exit $? |