0% found this document useful (0 votes)
14 views2 pages

#!binbash

This document is a Bash script for a Canteen Management System that allows users to display menu items, place orders, and view orders. It includes functions for each of these tasks and handles user input for menu selection and order quantities. The script runs in a loop until the user chooses to exit.

Uploaded by

nazimt22it
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

#!binbash

This document is a Bash script for a Canteen Management System that allows users to display menu items, place orders, and view orders. It includes functions for each of these tasks and handles user input for menu selection and order quantities. The script runs in a loop until the user chooses to exit.

Uploaded by

nazimt22it
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#!

/bin/bash

# Load configuration
source ./canteen_config.sh

# Function to display menu options


display_menu() {
clear
echo "Canteen Management System"
echo "-------------------------"
echo "1. Display Menu"
echo "2. Place Order"
echo "3. View Orders"
echo "4. Exit"
}

# Function to display menu items


display_menu_items() {
echo "Menu Items:"
for i in "${!MENU_ITEMS[@]}"; do
echo "$((i + 1)). ${MENU_ITEMS[i]} - \$${MENU_PRICES[i]}"
done
}

# Function to place an order


place_order() {
display_menu_items
echo "Enter your choice:"
read choice

if ((choice < 1 || choice > ${#MENU_ITEMS[@]})); then


echo "Invalid choice"
return
fi

item="${MENU_ITEMS[choice - 1]}"
price="${MENU_PRICES[choice - 1]}"

echo "Enter quantity:"


read quantity

if [[ ! $quantity =~ ^[0-9]+$ ]]; then


echo "Invalid quantity. Please enter a number."
return
fi

total=$((quantity * price))
echo "Ordered: $quantity x $item - Total: $total"
echo "$quantity x $item - $total" >> "$ORDERS_FILE"
}

# Function to view orders


view_orders() {
if [[ -f $ORDERS_FILE ]]; then
echo "Orders:"
cat "$ORDERS_FILE"
else
echo "No orders placed yet."
fi
}

# Main script
while true; do
display_menu
echo "Enter your choice:"
read option
case $option in
1) display_menu_items ;;
2) place_order ;;
3) view_orders ;;
4) echo "Exiting..."; break ;;
*) echo "Invalid choice. Please try again." ;;
esac
echo "Press Enter to continue..."
read
done

You might also like