2. Based on user feedback, delete the appropriate (Web site development)
2. Based on user feedback, delete the appropriate entries from the address book. Because the delete operation can potentially remove information from the address book, you have to be extra careful about making backups and working on copies of the original address book. To simplify prompting and printing error messages, this script uses the shell function library libTYSP.sh that was introduced in Chapter 21. The basic flow of the script is 1. Make a copy of the address book and use the copy for all modifications. 2. Get a list of all matching lines from this copy and store them in a deletion file. 3. For each line in the deletion file, print it out formatted and ask the user whether the line should be deleted. 4. If the user wants the line deleted, remove the line from the copy of the address book. 5. After all the deletions are performed, make a backup of the original address book. 6. Make the edited copy the address book. 7. Clean up temporary files and exit. For each of these steps, you use a function to make sure that the operations performed succeeded. The complete delperson script is given in Listing 22.4 (the line numbers are provided for your reference). Listing 22.4 Complete Listing of the delperson Script 1 #!/bin/sh 2 # Name: delperson 3 # Desc: del a person addressbook 4 # Args: $1 -> name of person to delete 5 6 # get the helper functions 7 8 . $HOME/lib/sh/libTYSP.sh 9 10 PATH=/bin:/usr/bin 11 12 # check that a name is given 13 14 if [ $# -lt 1 ] ; then 15 printUSAGE ” basename $0 name” 16 exit 1 17 fi 18
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.