Detecting Pipe Using Bourne Shell

Ian Fenn ifenn%ee.surrey.ac.uk at nss.cs.ucl.ac.uk
Fri Apr 7 01:53:08 AEST 1989


Hello all. I wonder if one of you can help me. I have a Bourne shell program 
which maintains a database of telephone numbers. If I enter the program with 
no arguments:

% phone

I display a main menu which offers options to change entries,
delete entries, etc, etc. If I enter the program with arguments:

% phone Bloggs

Then it searches through the database (using grep) for the arguments in the 
database of telephone numbers (in this example it would look for Bloggs). I 
test for arguments by using:

if test $# -ne 
then	.....search for arguments in database.....
	.....then exit
fi
....rest of program (i.e. Main Menu).

The only problem with this is that I cannot pipe the output from another 
program into it because it drops into the main menu and out again! Probably 
due to the test for arguments. Can anyone therefore tell me how to detect a 
pipe using Sh, so that the following will work? Or suggest another way 
round the problem?

% cat datafile | phone 

Thanks in advance.

--
Ian Fenn,                     +------------------------------------------------+
Computer System Technician,   |  Network Address : ifenn at ee.surrey.ac.uk       |
                              |  Telephone       : +44 483 571281  ext. 9104   |
Department of                 |  Direct line     : +44 483 509104              |
    Electrical Engineering,   |  Telex           : +44 859331                  |
University Of Surrey,         |  Fax             : +44 483 34139               |
Guildford,                    +------------------------------------------------+
Surrey.                       | "It is easier to change the specification to   |
GU2 5XH.                      |       fit the program than vice versa."        |
                              +------------------------------------------------+



More information about the Comp.unix.wizards mailing list