#!/bin/bash # vi:set ts=8 sw=4 et sta: # # Author: Clark J. Wang # # $Date$ # $HeadURL$ # $Revision$ # #--------------------------------------------------------------------# function BEGIN { if [ ! -e "$record_file" ]; then echo "$record_file not found" exit 1 fi } #-- main ------------------------------------------------------------# { BEGIN tmpfile=/tmp/delete.tmp while true; do clear echo "Delete Employee Record" echo "" while true; do echo -n "Enter a phone number (xxxxxxxx): " read phone_number if [ ! "$phone_number" ]; then echo "Phone number not entered" continue fi if ! echo $phone_number | grep -Eq '^[0-9]{8}$'; then echo "Invalid phone number" continue fi break done if grep "$phone_number" $record_file 2> /dev/null; then echo -n "Confirm deletion: (y)es or (n)o: " read confirm if [ "$confirm" != y -a "$confirm" != Y ]; then break fi sed -e "/^..-$phone_number:/d" "$record_file" > $tmpfile cat $tmpfile > "$record_file" echo -n "Delete another? (y)es or (n)o: " read confirm if [ "$confirm" = y -o "$confirm" = Y ]; then continue else break fi else echo "$phone_number not found" echo -en "\nPress Enter to continue..." read exit 1 fi done }