|
411, Directory Assistance Program:
bash/ksh.
|
SYNOPSIS: 411 <string>
This very simple shell program enables you
to find a telephone number in a database.
This database contains a record per line, and
you can request a record by typing any portion
of the line.
411 will return all records containing the string typed.
Also, 411 is case independent, as far as
it is concerned, "Luis" and "luis" are the same string.
Before showing any examples, here is the program:
#!/bin/bash
grep -y "$*" <<END
Pizza Hut delivery B:(317) 876-7676
Pharmacy Board (Indy) B:(317) 232-1140
John Little (Work) B:(812) 123-4567
Robin Hood (Work) B:(812) 987-3423
END
Line one tells the shell to execute this script using
/bin/bash, a Linux shell.
Lines two and seven are the program. Line two uses the
grep
command (see
man grep) to search the program's data for the
specified string.
The "<<END" and "END" in the second and last lines indicate
the beginning and the end of the program's data, lines three through six.
To execute 411, write the above script in a file called 411, and
make it executable (chmod +x 411). Insure that the directory
where 411 is located exists in your PATH, and type: "411 <string>"
at the shell prompt. Examples:
$ 411 John Little
John Little (Work) B:(812) 123-4567
$ 411 pizza
Pizza Hut delivery B:(317) 876-7676
$ 411 work
John Little (Work) B:(812) 123-4567
Robin Hood (Work) B:(812) 987-3423
$ 411 317
Pizza Hut delivery B:(317) 876-7676
Pharmacy Board (Indy) B:(317) 232-1140
This shell program came out of a book,
which I highly recommend:
THE UNIX PROGRAMMING ENVIRONMENT,
by Brian W. Kernighan and Rob Pike.