I\'m writing a bash shell script, and I\'m having problems with one particular a
ID: 3561999 • Letter: I
Question
I'm writing a bash shell script, and I'm having problems with one particular aspect of my program. My script refers back and forth to a data file, where it saves, finds, and erases data.
One selection in my menu allows the user to add an entry to the data file. While I think my script successfully does this, please let me know what I need to change if it doesn't. My main problem, however, lies in the next aspect of this menu selection. If you want to add an entry, and the entry already exists, the script should tell the user that the entry they're trying to create already exists. How can I go about doing this?
Here's my script as it stands so far:
#!bin/bash
echo " "
echo "MENU:"
echo "1: Add a record"
echo "2: Remove a record"
echo "3: Find a record"
echo "4: List all records"
echo "5: Exit"
echo "Enter your selection: "
read selection
case $selection in
1) echo "Enter Name"
read name
echo "enter email address"
read email
name "," email>>records.dat
;;
2) echo "Enter Name"
read name
cat records.dat | sed -e name>records.dat
;;
3) echo "Enter Name"
read name
grep name records.dat
;;
4) cat records.dat
;;
5) exit
;;
esac
Thank you in advance.
Explanation / Answer
[Ben] Well, let's see -
So far so good - BUT: