LDP/LDP/guide/docbook/abs-guide/pb.sh

51 lines
1.7 KiB
Bash
Raw Normal View History

2002-06-03 14:36:49 +00:00
#!/bin/bash
# pb.sh: phone book
# Written by Rick Boivie, and used with permission.
2005-06-05 14:39:50 +00:00
# Modifications by ABS Guide author.
2002-06-03 14:36:49 +00:00
2004-04-28 12:08:07 +00:00
MINARGS=1 # Script needs at least one argument.
2002-06-03 14:36:49 +00:00
DATAFILE=./phonebook
2004-04-28 12:08:07 +00:00
# A data file in current working directory
#+ named "phonebook" must exist.
2002-06-03 14:36:49 +00:00
PROGNAME=$0
2004-04-28 12:08:07 +00:00
E_NOARGS=70 # No arguments error.
2002-06-03 14:36:49 +00:00
if [ $# -lt $MINARGS ]; then
2007-04-26 21:13:49 +00:00
echo "Usage: "$PROGNAME" data-to-look-up"
2002-06-03 14:36:49 +00:00
exit $E_NOARGS
fi
if [ $# -eq $MINARGS ]; then
grep $1 "$DATAFILE"
2003-11-03 16:25:16 +00:00
# 'grep' prints an error message if $DATAFILE not present.
2002-06-03 14:36:49 +00:00
else
( shift; "$PROGNAME" $* ) | grep $1
# Script recursively calls itself.
fi
exit 0 # Script exits here.
2004-04-28 12:08:07 +00:00
# Therefore, it's o.k. to put
2008-03-13 13:24:45 +00:00
#+ non-hashmarked comments and data after this point.
2002-06-03 14:36:49 +00:00
# ------------------------------------------------------------------------
2004-04-28 12:08:07 +00:00
Sample "phonebook" datafile:
2002-06-03 14:36:49 +00:00
John Doe 1555 Main St., Baltimore, MD 21228 (410) 222-3333
Mary Moe 9899 Jones Blvd., Warren, NH 03787 (603) 898-3232
Richard Roe 856 E. 7th St., New York, NY 10009 (212) 333-4567
Sam Roe 956 E. 8th St., New York, NY 10009 (212) 444-5678
2003-08-25 14:48:48 +00:00
Zoe Zenobia 4481 N. Baker St., San Francisco, SF 94338 (415) 501-1631
2002-06-03 14:36:49 +00:00
# ------------------------------------------------------------------------
$bash pb.sh Roe
Richard Roe 856 E. 7th St., New York, NY 10009 (212) 333-4567
Sam Roe 956 E. 8th St., New York, NY 10009 (212) 444-5678
$bash pb.sh Roe Sam
Sam Roe 956 E. 8th St., New York, NY 10009 (212) 444-5678
2004-04-28 12:08:07 +00:00
# When more than one argument is passed to this script,
2003-11-03 16:25:16 +00:00
#+ it prints *only* the line(s) containing all the arguments.