1

I've made a simple program to order food, I've gotten very far for someone who has only had a few days to learn this. (considering I'm not a programmer at all). I want the first part of my program to allow 'Order' or 'order', then 'Quit' or 'quit', which works fine. I then want it to have a message that the input is not valid if neither are entered. What is the best way to get around it? This is in Shell Script

clear
read -rp "Do you want to order or quit?" start
    if echo "$start" | grep -iq 'order'; then
    continue
    elif echo "$start" | grep -iq 'quit'; then
    exit 0
    else echo "Please order or quit";
fi

echo "Please enter your name"
read name
echo "What is your phone number"
read number
echo "What kind of fruit do you want?"
read fruit
echo "How much KG do you want?"
read kg

echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
echo  "Hello" $name" here is a summary of your order:"
date
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
echo "Your phone number is:" $number
echo "You have ordered" $kg "kg of" $fruit
echo $fruit "is £4 a kilogram, so you will pay"
expr 4 \* $kg

while true; do
read -rp 'Would you like to order again?' order
if echo "$order" | grep -iq 'yes'; then
    exec $0
elif echo "$order" | grep -iq 'no'; then
     exit 0
else echo "Please say Yes or No";
fi
done
0

Good work on your script. You can check if neither input is valid like this:

# change lowercase to uppercase
start=`echo $start | tr "[a-z]" "[A-Z]"` 

# exit if start isn't either "ORDER" or "QUIT"
if [ $start != "ORDER" ] && [ $start != "QUIT" ]
then
    echo "Your input was not correct"
    exit
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.