You are not logged in.
I'm learning how to script ( well trying ) and i can't get my script to exit when i type "q",I've been at this for a while and can't figure out what I'm doing wrong.
#!/bin/bash
########################################################################################################
#------------------------------------------------------------------------------------------------------#
#
# File Name: Course-Project
#
# ADDRESS-BOOK / CONTACT-MANAGER
#
# Discription: This will be a menu-based program, with a main screen offering options to create,view,
# search for and delete contacts.
#
#------------------------------------------------------------------------------------------------------#
########################################################################################################
# Variable that holds my database information
fname=names.dat
[ -f $fname ] || > $fname
while true
do
# Database Menu
echo "1. Create a record"
echo "2. View records"
echo "3. Search for records"
echo "4. Delete records that match a pattern"
echo "q. Type \"q\"to quit"
echo
echo -n "Enter number here: "
read number
case $number in
1)
# Ask for first name
echo
echo -n "Enter First Name: " ; read name
# Ask for Surname
echo -n "Enter Surname: " ; read surname
# Ask for address
echo -n "Enter Address: " ; read address
# Ask for city
echo -n "Enter City: " ; read city
# Ask for province
echo -n "Enter Province: " ; read province
# Ask for postal-code
echo -n "Enter Postal-Code: " ;read postal
# Group these commands together and redirect the output to a variable, fname with a value of names.dat
(echo $name : $surname : $address : $city : $province : $postal) >> $fname
# Display the contents of the database
echo
(
echo
echo "Database Contents: "
echo
cat $fname
) | less
cat $fname
# Number of contacts in the database
echo
echo -n "Nunber of contacts in the database: "
cat $fname | wc -l
echo
;;
2)
cat $fname | less
;;
3)
echo "This option is not yet available"
;;
4)
echo "This option is not yet available"
;;
*)
echo "Invalid choice"
;;
q*|Q*)
exit
;;
esac
echo -n "Press enter to continue: " # This will let you view any output before clearing the screen
read x
clear
done
Thanks
Last edited by unilx (2011-06-23 05:36:34)
Offline
q*|Q*) should be put before *)
This silver ladybug at line 28...
Offline
case stops matching patterns as soon as one is successful. The * pattern should be the last.
Also you should quote your variables and improve your indentation.
Check out: http://mywiki.wooledge.org/BashGuide alongside with BashFAQ and BashPitfalls on the same page.
don't drink unwashed fruit juice.
i never make predictions, especially about the future.
Offline
Thanks, moving the *) to the bottom of the case statement did the trick.
Offline