Sams Teach Yourself Shell Programming in (Make my own web site) 24 Hours

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 22: Problem Solving with Shell Scripts Previous Chapter Next Chapter Sections in this Chapter: Moving Directories Questions Maintaining an Address Book Terms Summary Previous Section Next Section Questions 1. How might you simplify the following portion of the mvdir script? Specifically, how could you rewrite the main if statement, such that the else clause was unnecessary? 40 if [ -d “$2″ ] ; then 41 42 DESTDIR= ( cd “$2″ ; pwd ; ) 43 44 else 45 46 # if the destination doesn’t exist then 47 # assume the destination is the new name 48 # for the directory 49 DESTDIR=” /usr/bin/dirname $2 ” 50 NEWNAME=” /bin/basename $2 ” 51 52 # if dirname returns a relative dir we will 53 # be confused after cd’ing later on. So 54 # reset it to the full path. 55 DESTDIR= (cd $DESTDIR ; pwd ; ) 56 57 # if the parent of the destination doesn’t 58 # exist, we’re in trouble. Tell the user 59 # and exit. 60 if [ ! -d “$DESTDIR” ] ; then 61 printERROR “A parent of the destination directory $2 does not exist” 62 fi 63 64 fi 65 2. The showperson script lists all matching entries in the address book based on a name provided by the user. The matches produced are case sensitive. How can you change the matches so they aren’t case sensitive? 3. Both the showperson and delperson scripts reproduce exactly the following pieces of code PATH=/bin:/usr/bin # check that a name is given if [ $# -lt 1 ] ; then printUSAGE ” basename $0 name” exit 1 fi # check that the address book exists
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Leave a Reply