Question: All code must be done in Shell Script Your task for Part 1 is to write the following functions: 1. function usage { .. }
All code must be done in Shell Script
Your task for Part 1 is to write the following functions: 1. function usage { .. } The purpose of the function `usage` is to check whether or not that the script is used correctly. The correct usage should be: ./GenerateStatement [-o outputfile] [-t tipamount] guestlist Your script should detect an illegal usage of your scripts options on the command line. For example, if a user typed: $ ./GenerateStatement -o $ ./GenerateStatement -o output -p Your script should print out an error message explaining the appropriate usage of your script. Additionally, the `usage` function will check whether or not the flags have an invalid, or missing arguments, in which case you must display the `$USAGE`, and `exit 1`.
In order to write this functionality, you will need to use the `getopts` functionality. Using if-statements will not be sufficient, and you will be docked. If you are confused on how to use `getopts` please refer to this documentation: 2. function parse_guests { .. } The purpose of the function `parse_guests` is to take the guestlist input, and store it into the $GUEST array. The guestlist file will always have each name separated by a new line. For example: Charly Alex Eric Lucy Priyanka To help you with this function, you can use the `read` and `while` commands to input each name into $GUEST. 3. function print_guest { .. } The purpose of the function `print_guest_list` is print out all the elements inside the $GUEST array. The output for this function, using the example given in `parse_guest_list` should look like the following: Charly Alex Eric Lucy Priyanka
================================= End of Part 1===================================
Part 2 For the second part, you will need to be able to calculate all the costs (including with the -t option flag), and produce a statement either to the terminal or a file with the -o option flag. Keep in mind, Part one has provided you with helper functions that can make this portion a lot simpler. function calc { .. } The purpose of this function is to perform all of the budget calculations. You can use any method of calculating, but we recommend using the `expr` command or `bc`. Additionally, the `calc` function read in the total cost of the purchase, and store it into $cost_in_cents. You will need to calculate the values for the following given variables: $limit # the upper bound for your budget (# of guest * cost per person) $cost # actual cost of the purchase $tip # the total cost * your tip percentage $overall_cost # total cost + tip $average_cost # overall_cost / total guests We have provided all of the base strings you can use to help match with the solution code. Do not edit the given strings, because the test-cases are very sensitive to the ones that we provided. function print_message { .. } This function is given to you. This will print out the statement with the correct variables. Use this at the end when you want to test or debug. Do not change the strings in this function, as it will affect the outcome of the test scripts. ~~END OF PART 2~~
#!/usr/bin/env bash #filename: GenerateStatement.sh #description: TODO #author: TODO #date: TODO MM/DD/YYYY #=============================================================================== # usage message USAGE="Usage: ./GenerateStatement.sh [-t
# array for guests GUESTS=()
# option arguments percent=20 # default: 20 percent outfile= # default: print to stdout
# event info EVENT="Coding Challenge at USSD" LOCALE="Fakhourian Theater, University of Southern Los Angeles" DATE="Saturday, March 25, 2017" TIME="10:00am - 7:00pm" VENDOR="Gary's Secret Kitchen" # $$$$ but very good food BUDGET_PER_PERSON=25 EVENT_INDEX="Reimbursement Office"
# variables to populate. do not change here. do so in function `calc` num_guests=DO_NOT_CHANGE_HERE # number of elements in ${GUESTS} limit=DO_NOT_CHANGE_HERE # $num_guests * $BUDGET_PER_PERSON cost=DO_NOT_CHANGE_HERE # prompt user tip=DO_NOT_CHANGE_HERE # $cost * $percent% overall_cost=DO_NOT_CHANGE_HERE # $cost + $tip average_cost=DO_NOT_CHANGE_HERE # $overall_cost / $num_guests
#------------------------------------------------------------------------------- #function: usage #description: #------------------------------------------------------------------------------- function usage { #TODO for Part1 : }
#------------------------------------------------------------------------------- #function: parse_guests #description: #------------------------------------------------------------------------------- function parse_guests { #TODO for Part1 : }
#------------------------------------------------------------------------------- #function: print_guests #description:
function print_guests { #TODO for Part1 : }
#------------------------------------------------------------------------------- #function: convert #description: #------------------------------------------------------------------------------- function convert { #TODO for Part1 : }
#------------------------------------------------------------------------------- #function: calc #description: #------------------------------------------------------------------------------- function calc { echo -n "What is the total cost in cents (not including tip)? "; read cost_in_cents
#TODO for part2 : }
#------------------------------------------------------------------------------- #function: print_message #description: DO NOT CHANGE / EDIT #------------------------------------------------------------------------------- function print_message { # print header: echo -e "Date: $DATE" echo -e "Event: $EVENT" echo -e "Vendor: $VENDOR" echo -e "Locale: $LOCALE" echo "--------------------------------------------------------------------" echo
# print list of guest echo "In Attendance:" print_guests echo # reimbursement details echo -n "Allotment: $num_guests participants " echo "($num_guests x \$$BUDGET_PER_PERSON.00 = $limit)" echo "Reimbursement request: $overall_cost" echo "Paid: $cost + $tip tip: $overall_cost" echo "Spent: $num_guests at $average_cost per person" echo "Please charge $overall_cost" to $EVENT_INDEX
#------------------------ the script starts here ----------------------------- usage $@ ~
EXAMPLE RUN
# content of file called `list` Alexander Hamilton Aaron Burr John Lawrence Hercules Mulligan George Washington James Madison Thomas Jefferson $ ./GenerateStatement.sh -o output list What is the total cost in cents (not including tip)? 3423 $ ls GenerateStatement.sh output $ cat output Date: Saturday, March 25, 2017 Event: Coding Challenge at USSD Vendor: Gary's Secret Kitchen Locale: Fakhourian Auditorium, University of Southern Los angeles
--------------------------------------------------------------- In Attendance: Alexander Hamilton Aaron Burr John Lawrence Hercules Mulligan George Washington James Madison Thomas Jefferson Allotment: 7 participants (7 x $25.00 = $175.00) Reimbursement request: $41.07 Paid: $34.23 + $6.84 tip: $41.07 Spent: 7 at $5.86 per person Please charge $41.07 to CSE Student Affair
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
