Friday, August 10, 2012

Bash shell scripting exercises II : practice with arrays, functions, arrays, and other shell script features


This is from a little course I prepared Linux exercises for

Purpose:
Practice using functions, arrays and other shell script features

Your task is to write a checkbook program. Make sure you read the following directions carefully and implement the script according to these specifications. Failure to do so will cost you points.

Script name: checkbook.sh
Positional parameters: account
Example call:

./checkbook.sh myacct


Part 1)

Below  is a sample xml record which your program must be able to parse. Store the records into an array and write a function to print out each record. Pretty print the records, that is, have a column names at the top. You program must support an unsorted file that could have any number of records.

Here is a simple xml file with only one record:

<array>
<dict>
<key>Id</key>
<string>1</string>
<key>Type</key>
<string>credit</string>
<key>Date</key>
<string>10108</string>
<key>Details</string>
<string>New Account</string>
<key>Amount</key>
<string>500.00</string>
<key>Rec</key>
<string>1</key>
</array>

It has 6 attributes: Id, Type, Date, Details, Amount, and Rec. It has 1 value for each attribute: 1, credit, 10108, New Account, 500.00, and 1. You can assume that each tag is open and completed on a single line and that each key is followed immediately by its value.

For instance, the tag <key> is represented by <key>Amount</key> and its value is <string>500.00</string> .

Dates are formatted this way: mmddyy (mm should be one character if it's before 1 digit)

Tools recommended for this part: grep, cut, and loops




Part 2)

Complete the script by writing a menu-based system that has the following features.

1. Set the active year--> this directs how other functions behave

2. View the records for a month --> You should pretty print each record from the month a user specifies and also show the monthly average, high, low,  and total.

3) Add new records --> be able to add a new record and store your arrays

4) Save your records --> be able to dump your records to the same file you opened with the same format.

5) Support new accounts --> if a calls checkbook.sh with a filename that does not exist, use that as a new account

Your program should be user friendly and have error handling.

Tools recommended for this part: select, bc


***Extra Credit***

Add a reconciling feature
Also, allow the user to draw a graph of the year's activity (based on amount)

No comments:

Post a Comment