Shell Functions  «Prev  Next»

Script that uses Functions - Exercise

Script that uses functions

Objective: Sort a set of function definitions and calls into correct order
This exercise uses a Java applet to rearrange the steps in this process. If you do not have Java active in your browser or are behind a firewall that does not allow Java applets you will not be able to complete this exercise. If you do not see the applet below click OK I'm Done to continue with the course. You will receive full credit for this exercise.

Instructions

Below are six steps required to write a shell script containing two functions called function1 and function2, but they are presented out of order. You'll see that function1 is called from function2. Drag the steps into the correct order, with the first step at the top of the list. When you have the steps in order, click Done. You'll see whether or not the order is correct. If you didn't get the order right, keep trying. If you get stuck, try clicking Hint. The steps you have in the correct place will have green lights next to them. The steps that are not in the correct place will have red lights next to them. When you're ready for an explanation, click the OK, I'm Done button.

Exercise scoring

Applet coding instructions (sample format shown below).
Initial order in applet:
function2 ()
function1 ()
function2
<the next 4 lines are one step>
{
echo “This is function 2”
function1
}
<the next 3 lines are one step>

{
echo “This is function 1” 
}
#! /bin/sh
Correct order:

#! /bin/sh
function1 ()
{

echo “This is function 1”
}
function2 ()
{

echo “This is function 2”
function1
}
function2