Starting from:

$30

CS2211- Assignment 2 Solved

QUESTION 1 (25 marks)
Write a Bourne shell script lastarg, which takes 0 or more arguments and prints the last (rightmost) argument in the argument list. You can assume that arguments will be made up of letters and digits only. 

Note that, the number of arguments can be more than 10. For example, the output of

lastarg arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 arg11

 

should be

arg11

If no argument is provided, simply return nothing.

You should write enough inline comments inside your shell script to explain each part of it.

In your report, you should include actual test cases (as well as sample outputs) to demonstrate all possible
options in your program.

If lastarg is placed in your home directory, what will happen if you execute the following command?  Show the output and explain why you got this output.

cd; lastarg .*

 

QUESTION 2 (25 marks)
Write a Bourne shell script odd_prn, which echoes its shell script file name as well as the values of its odd arguments. Even arguments should be ignored. Each value should be echoed in a separate line. You can assume that arguments will be made up of letters and digits only. Note that, the number or arguments can be even or odd. Note also that, the number of arguments can be more than 10. For example, the output of:

odd_prn to C or not to C that is the question 

should be

odd_prn  to  or  to  that  the 

If no argument is provided, simply return the shell script file name only.

You should write enough inline comments inside your shell script to explain each part of it.

In your report, you should include actual test cases (as well as sample outputs) to demonstrate all possible cases in your program.

If odd_prn is placed in your home directory, what will happen if you execute the following command?  Show the output and explain why you got this output.

cd; odd_prn .*

QUESTION 3 (50 marks)
Draw a flow chart and write a Bourne shell script that causes the following output (below) to be displayed. 

Note that, there is a single space between each value.

The number of column should be taken as an input during execution. 

For example, if the input to the program is 6, the program should produce the following output:

0
0 1 

0 1 2

0 1 2 3

0 1 2 3 4

0 1 2 3 4 5 

0 1 2 3 4 

0 1 2 3 

0 1 2
0 1 
0
You should write enough inline comments inside your shell script to explain each part of it.

In your report, you should include actual test cases (as well as sample outputs) to demonstrate all possible cases in your program.

 

             

More products