-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindCust
executable file
·67 lines (61 loc) · 2.14 KB
/
FindCust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Kevin Fan (26/4/17)
# Description: This script allows the user to search for an existing customer based upon
# any of the customers personal information
# Clear the console
clear
# Function that ask for user for search term and and then call the checkInput option
function readInput
{
#Asks user for search term
printf "\nPlease enter any of the customer information to search for: "
#Takes in serch term as parameter
read input
checkInput
}
# Function that checks the search term input and displays relevant options
function checkInput
{
# If no input is detected, the readInput function is called again for user to re-enter
if [ -z $input ]; then
clear
printf "\n\tNo entry detected. Please re-enter search term\n"
readInput
# If matches are found, the mathces are displayed, and the actionAfterSearch is called
elif [[ $(grep -i -c $input CustomerDetails) -ne 0 ]]; then
printf "\n$(grep -i -c $input CustomerDetails) match(s) were found:\n"
grep -i $input CustomerDetails
actionAfterSearch
# If no matches are found, the actionAfterSearch is called
elif [[ $(grep -i -c $input CustomerDetails) -eq 0 ]]; then
printf "\nNo matches were found\n"
actionAfterSearch
fi
}
# Function that displays options for user after the first search
# Users can perform another search or return to main menu
function actionAfterSearch
{
# Local variable to control while loop
validChoice=false
while [[ $validChoice = false ]]; do
printf "\nPerform another search (Y/N):"
read choice
clear
# User choice to converted to upper case, and if its Y then set the validChoice varible to valid to exit loop and call the readInput function
# to search again
if [[ ${choice^^} = 'Y' ]]; then
validChoice=valid
readInput
# User choice to converted to upper case, and if its Y then set the validChoice varible to valid to exit loop and return to menu script
elif [[ ${choice^^} = 'N' ]]; then
validChoice=valid
else
# All other cases print out invalid option
printf "\nNot a valid option"
fi
done
}
# Calls the readInput function that begins the search loop. This loop is exited to main menu
# only at revelvant options
readInput