SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id") echo "$SERVICES" | while read SERVICE_ID BAR NAME do if [[ -n $SERVICE_ID ]] then echo "$SERVICE_ID) $NAME" fi done read SERVICE_ID_SELECTED if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]] then MAIN_MENU "I could not find that service. What would you like today?" return fi SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED") if [[ -z $SERVICE_NAME ]] then MAIN_MENU "I could not find that service. What would you like today?" return fi SERVICE_NAME=$(echo $SERVICE_NAME | sed -E 's/^ *| *$//g') echo -e "\nWhat's your phone number?" read CUSTOMER_PHONE CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'") if [[ -z $CUSTOMER_NAME ]] then echo -e "\nI don't have a record for that phone number, what's your name?" read CUSTOMER_NAME INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')") fi CUSTOMER_NAME=$(echo $CUSTOMER_NAME | sed -E 's/^ *| *$//g') CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'") CUSTOMER_ID=$(echo $CUSTOMER_ID | sed -E 's/^ *| *$//g') echo -e "\nWhat time would you like your $SERVICE_NAME, $CUSTOMER_NAME?" read SERVICE_TIME INSERT_APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')")