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. Place the steps into the correct order, with the first step at the top of the list.
When you have the steps in order, paste them into the text box and press submit.

Exercise scoring


<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