Chris F.A. Johnson
Unix shell programming notes

13 August 2012

ph - a simple phone book

Originally written for the Amiga, ph was completely rewritten in August 2000 as a pair of Unix shell scripts. A third script, phdel, was added 11 February 2004.

Author, copyleft

Written (copyright 2000, 2004) by Chris F.A. Johnson, and released under the terms of the GNU General Public License, a.k.a. "copyleft".

Features

New in version 0.2

Usage

Options

Examples

Files

System-wide data file
/info/data/phones
This is a non-standard directory, and can be changed by altering the references in each of the scripts.
Each user has a data file:
$HOME/.phones

History

These started out as one-liners on the Amiga, where they served me well for almost 15 years. When I finally put Ami to rest and moved over to a Linux box, I converted them to Unix shell scripts:

phadd
echo "$*" >> $HOME/.phones
ph
grep -i "$*" $HOME/.phones

I copied the phone file from my Amiga, and it was business as usual.

Although my computer is primarily a single-user machine, it is on a LAN, and other people do have accounts on it; therefore, I thought it would be useful to expand ph so that it could be used by everyone.

The changes required were very simple:

  1. add a generally accessible file to contain system-wide phone numbers
  2. add that file to the search (grep) command
  3. write a method for adding new information to the system-wide file
  4. check that the data files exist, and create them if they don't
While I was at it, I changed grep to egrep to allow multiple search criteria.

The scripts

ph

  #!/bin/sh
  # Mon Aug 28 12:52:49 EDT 2000

  # ph - a simple phone book - version 0.2
  # Copyright 2000, Chris F.A. Johnson
  # released under the terms of the
  # GNU General Public Licence

  phbase="/info/data/phones $HOME/.phones"

  for f in $phbase
  do
    if [ ! -f $f ]
    then
      touch $f
    fi
  done

  egrep -ih "$@" $phbase

phadd

#!/bin/sh
# Mon Aug 28 13:08:54 EDT 2000

# phadd - script to add phone numbers to:
# ph - a simple phone book - version 0.2
# Copyright 2000, Chris F.A. Johnson
# released under the terms of the
# GNU General Public Licence

if [ "$1" = "-s" ]
then
  phlist="/info/data/phones"
  shift
else
  phlist="$HOME/.phones"
fi

echo "$@" >> $phlist

phdel

#!/bin/sh
# Wed Feb 11 02:54:00 EST 2004
# NAME: phdel
# Copyright 2004, Chris F.A. Johnson
# Released under the terms of the
# GNU General Public License

if [ "$1" = "-s" ]
then
  phlist=/info/data/phones
  shift
else
  phlist=$HOME/.phones
fi

grep -iv "$1" $phlist > /tmp/phdel$$
mv /tmp/phdel$$ $phlist

The future of ph

Over the years, I have had many ideas for improvements to ph, from adding dialing, to making it into a full-fledged address and phone book, and even adding a GUI interface. But I have downloaded many address book programs over the years, and none of them ever caught my fancy. So why would I want to make ph more like them?

In the end, I always decided to leave it alone. It is simple and it is very quick, and it does what I need .

Conclusion

Writing this documentation and HTML page was much more work than writing the scripts!

Recommended reading

Some of the philosophy behind ph can be found in the Software Toolbox.

Modified 22 Sep 2013