I try to do exercise about Learn Bash and SQL by Building a Bike Rental Shop - Build a Bike Rental Shop until the exercise: Move the echo
command that prints all the available bikes below the message you just added, i try do add echo "$AVAILABLE_BIKES"
, it was true but I try to click Run to pass it was error many times: `. I tried to reset many times and do again but was error many times.
Here is my source code:
#!/bin/bash
PSQL="psql -X --username=freecodecamp --dbname=bikes --tuples-only -c"
echo -e "\n~~~~~ Bike Rental Shop ~~~~~\n"
MAIN_MENU() {
if [[ $1 ]]
then
echo -e "\n$1"
fi
echo "How may I help you?"
echo -e "\n1. Rent a bike\n2. Return a bike\n3. Exit"
read MAIN_MENU_SELECTION
case $MAIN_MENU_SELECTION in
1) RENT_MENU ;;
2) RETURN_MENU ;;
3) EXIT ;;
*) MAIN_MENU "Please enter a valid option." ;;
esac
}
RENT_MENU() {
# get available bikes
AVAILABLE_BIKES=$($PSQL "SELECT bike_id, type, size FROM bikes WHERE available = true ORDER BY bike_id")
echo "$AVAILABLE_BIKES"
# if no bikes available
if [[ -z $AVAILABLE_BIKES ]]
then
# send to main menu
MAIN_MENU "Sorry, we don't have any bikes available right now."
else
# display available bikes
echo -e "\nHere are the bikes we have available:"
echo "$AVAILABLE_BIKES"
# ask for bike to rent
# if input is not a number
# send to main menu
fi
}
RETURN_MENU() {
echo "Return Menu"
}
EXIT() {
echo -e "\nThank you for stopping in.\n"
}
MAIN_MENU
Here is my screenshot:
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Challenge: Learn Bash and SQL by Building a Bike Rental Shop - Build a Bike Rental Shop
Link to the challenge: