Debian Codegraph @

pb.sh

raw symbols SCIP
1 #!/bin/bash
2 # pb.sh: phone book
3
4 # Written by Rick Boivie, and used with permission.
5 # Modifications by ABS Guide author.
6
7 MINARGS=1 # Script needs at least one argument.
8 DATAFILE=./phonebook
9 # A data file in current working directory
10 #+ named "phonebook" must exist.
11 PROGNAME=$0
12 E_NOARGS=70 # No arguments error.
13
14 if [ $# -lt $MINARGS ]; then
15 echo "Usage: "$PROGNAME" data-to-look-up"
16 exit $E_NOARGS
17 fi
18
19
20 if [ $# -eq $MINARGS ]; then
21 grep $1 "$DATAFILE"
22 # 'grep' prints an error message if $DATAFILE not present.
23 else
24 ( shift; "$PROGNAME" $* ) | grep $1
25 # Script recursively calls itself.
26 fi
27
28 exit 0 # Script exits here.
29 # Therefore, it's o.k. to put
30 #+ non-hashmarked comments and data after this point.
31
32 # ------------------------------------------------------------------------
33 Sample "phonebook" datafile:
34
35 John Doe 1555 Main St., Baltimore, MD 21228 (410) 222-3333
36 Mary Moe 9899 Jones Blvd., Warren, NH 03787 (603) 898-3232
37 Richard Roe 856 E. 7th St., New York, NY 10009 (212) 333-4567
38 Sam Roe 956 E. 8th St., New York, NY 10009 (212) 444-5678
39 Zoe Zenobia 4481 N. Baker St., San Francisco, SF 94338 (415) 501-1631
40 # ------------------------------------------------------------------------
41
42 $bash pb.sh Roe
43 Richard Roe 856 E. 7th St., New York, NY 10009 (212) 333-4567
44 Sam Roe 956 E. 8th St., New York, NY 10009 (212) 444-5678
45
46 $bash pb.sh Roe Sam
47 Sam Roe 956 E. 8th St., New York, NY 10009 (212) 444-5678
48
49 # When more than one argument is passed to this script,
50 #+ it prints *only* the line(s) containing all the arguments.