OPS435: Assignment #2


General Description

Create a Bash shell script to help users record and track payments to vendor accounts.

Due Date

Monday April 12, 2010 @ 11:59:59 p.m.


You have been approached by the "payments section" of the purchasing department to write a portable Bash shell script called makePayments.bash to simplify making payments to their vendors. Vendors are companies that we have purchased goods and services from and may owe them money.

One section of the purchasing department records purchases made from vendors on account. We don't worry about this, it is done by someone else, but we need to use this purchases file. We can assume that purchases from vendors have already been included in a file that contains the following fields:

Your shell script will only accept two arguments: an existing file pathname (purchases file), and the payments file (does not have to exist). If your shell script is issued with any other number of arguments than 2, then the shell script will display a USAGE stderr message, and exit the shell script with a false value.

If the shell script contains two arugments with the first argument as a valid file pathname, then the user will be presented with a menu to

  1. Make a Vendor Payment
  2. Display Vendor Purchases
  3. Display Payments to Vendors
  4. Exit

The menu should only accept valid numbers for the menu, and display a message into indicate that the select is not valid (but NOT exit the script). Below are descriptions how each menu item should function.

If the user presses <ctrl><c> at any time during the program, the screen will clear and indicate that the program has been aborted, temporary files have been removed, and prompt the the user to press the ENTER key to exit the program...


When this menu item is selected, the screen clear and the user will be prompted for a vendor number. Only valid vendor numbers consist of an UPPERCASE letter followed by three numbers. If the user enters an invalid vendor number, or the vendor number does NOT exist in the purchases file, then the user will be prompted repeatly. Upon entry of an valid and existing vendor number, then all of the purchases (on separate lines) will be displayed showing a line number, the invoice number, and the amount of purchase.

The user is then prompted to type in the invoice number, and amount of payment. You can assume the user can make only one payment at a time, and you are not reqruired to error-check for negative payments. If you are required to make multiple payments, then the user must select another vendor payment from the main menu.

When the payment is completed, the system will indicate that the payment has been recorded, the payment will be added to the bottom of the payments file, and your script will pause for the user to press <ENTER> to return to the main menu.


When this menu item is selected, the screen is cleared, and the purchases datebase file is read to display the vendor's full name, and the total purchase amount owed (note: there could be more than one purchase transacations from the same vendor). Refer to the HINT and TIPS section to see how to determine the total amount owed to vendors.


When this menu item is selected, the screen is cleared, and the payments database file is read to display the vendor's full name, and the total payments made to the vendor (note: there could be more than one payment made to the same vendor). Refer to the HINT and TIPS section to see how to determine the total amount owed to vendors.


When this menu item is selected, the screen is cleared, and the script informs the user that the application has exited. The program should terminate with a true exit status.


[ run1.txt ] Incorrect number of arguments
[ run2.txt ] Invalid purchases database filename
[ run3.txt ] User presses <ctrl><c>
[ run4.txt ] Invalid Vendor Number, Non-Existent Vendor, and Valid Payments
[ run5.txt ] Additional Payment Transcations


  • You are NOT allowed to use zenity for this assignment. You will use read and echo, or other Linux commands. The assignment submission program will NOT allow shell script with Zenity command to be contained in your shell script (even as comments)...

  • You must have at least one function to define and execute in your shell script.

  • Use a loop to keep repeating the menu items until the user enters the 4th menu item. It is recommended to use a case statement for the different actions.

  • You MUST use the awk utility to generate the purchases and payments reports. Use the printf command within awk to make your purchase amounts align properly.

  • Make certain to remove ALL temporary files upon exit, or if you abort the shell script by pressing <ctrl><c>

  • It is recommended to use temporary files when matching valid vendor names to display the invoice and purchase amount information. You can then use command substitution and the set command to store vendor purchase information as positional parameters, and then use the for loop to display (hence number) each line...

  • Use redirection to create payments made by the user to the appropriate file.

  • You will notice that when generating the payments report, it only displays the total amount of payments for vendors. In other words it doesn't display each separate payment, just the total for EACH vendor...

    Here is a little script that demonstrates how to perform this task. Study this attachment, and then incorporate into your own shell script...

    (Trick) How to Generate Totals: [ trick.bash.txt ]


You MUST run the program below to submit your assignment (no exceptions). The following table displays which command to run to submit your assignment #2 (when available).

Linux Command:



  1. Shell scripts are to be submitted from your Matrix account from the submission scripts displayed above – no exceptions.

  2. If you do not submit your shell script on time, there will be a 10% penalty.

  3. Late assignments will carry a penalty of 10% per day. Since assignment is submitted electronically: weekends count!.

  4. If your script is not functional when tested, or produces too many incorrect answers, it will receive a mark of zero and must be resubmitted with in 7 days. Once resubmitted, such assignments can receive a maximum of 55%.

  5. Every assignment will be checked for plagiarism. If any copying is discovered, both students will receive a mark of 0
    and a "Dishonesty Report" will be entered in both student's files.

Good Luck :)