Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your task for Part 1 is to write the following functions: 1. function usage { ..

ID: 3824708 • Letter: Y

Question

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 script’s 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

#########CODE TO FIX##################################
just add where ever part 1 its stated

USAGE="Usage: ./GenerateStatement.sh [-t <percent>] [-o <output-file>] <guest-list>"

# array for guests
GUESTS=()

# option arguments
percent=20 # default: 20 percent
outfile= # default: print to stdout

# event info
EVENT="Coding Challenge at USSD" # USSD -- our imaginary rival school
LOCALE="Fakhourian Theater, University of Southern San Diego"
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="UCSD 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:

Explanation / Answer

CODE FOR PART 1 TASK:

CODE:

#!/bin/bash

#-------------------------------------------------------------------------------
#function: usage
#description: This functon is called when argumants are passed incorrectly
#-------------------------------------------------------------------------------
usuage(){
echo "Correct usuage of the script:"
echo "Usage: ./GenerateStatement.sh [-t <percent>] [-o <output-file>] [-g <guest-list>]"
exit 1
}

#-------------------------------------------------------------------------------
#function: while loop
#description: Checks argumants are passed correctly. If arguments are passed
#incorrectly it calls function 'usuage'
#-------------------------------------------------------------------------------
while getopts ":t:o:g:" opt; do
case $opt in
t)
echo "percent=$OPTARG" >&2
export percent=$OPTARG
;;
o)
echo "outfile=$OPTARG" >&2
export outfile=$OPTARG
;;
g)
echo "guestlist=$OPTARG" >&2
export guestlist=$OPTARG
;;
?)
echo "Invalid option: -$OPTARG" >&2
usuage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usuage
;;
esac
done

#Checks all the required variables have value or not. If not it calls the function 'usuage'
if [[ -z $percent || -z $outfile || -z $guestlist ]];then
usuage
fi

export GUEST_TEMP=""
#Initiating GUEST array
set -A GUEST
#---------------------------------------------------------------------------------------
#function: parse_guests
#description: Gets all the guests name from the input file and stores into 'GUEST' array
#---------------------------------------------------------------------------------------
parse_guests(){
guestlist_file=$1
while read line
do
GUEST_TEMP=`echo "$GUEST_TEMP $line"`
done < $guestlist_file
GUEST_TEMP=`echo $GUEST_TEMP | cut -c1-`
GUEST=($GUEST_TEMP)
}

#--------------------------------------------------------------------------------------
#function: print_guest
#description: Prints the 'GUEST' array
#--------------------------------------------------------------------------------------
print_guest(){
echo ${GUEST[@]}
}

#calling functions
parse_guests $guestlist
print_guest

--------- END OF CODE -------

Please let me know for more help