Modify rolo from this chapter so that a person running the program can keep their phone book file in whatever directory they prefer. This can be done by requiring that the user have set a variable called PHONEBOOK to be the name of the phone book file. Check to make sure that it's a valid file and default to the phone book file being in their $HOME directory if the variable's not set.

Here is an example:
$ PHONEBOOK=/users/steve/personal lu Gregory
Gregory 973-747-0370
$ PHONEBOOK=/users/pat/phonebook lu Toritos
El Toritos 973-945-2236
$
In the preceding example, we assume that the user steve has been granted read access to pat's phone book file.
Solution


This is easily done using the same variable assignment shown in example 1 of this chapter, so the key line is
phonebook=${PHONEBOOK:-$HOME/phonebook}
Then a test to see if it exists and is readable can be combined in a single conditional:
if [ ! -r $phonebook ] ; then
echo "Error: $phonebook doesn't exist or isn't readable"
exit 1
f

Computer Science & Information Technology

You might also like to view...

In a typical LAN, the firewall is the only protection from the Internet for local devices.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Cybercrime laws are consistent between states and countries, making it easy to reach a consensus as to what is illegal.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Match the following results with the proper formulas:

I. January II. Wednesday III. December IV. Saturday V.1 A.= Month Name(1) B.= Weekday Name(4) C.=Month Name(12) D.= Weekday Name(7) E.= Date Part ("m",#01/16/1959#)

Computer Science & Information Technology

Which of the following is most likely to be used for mobile phone payments?

A. Token ring B. Bluetooth C. IrDA D. NFC

Computer Science & Information Technology