Checking for Mail Waiting: msgchk

[previous] [next] [table of contents] [index]

The msgchk command will tell you whether there's mail waiting for you. Here's an example:

% msgchk
You have new mail waiting; last read on Mon, 09 Jan 1995 14:37:09
Many UNIX hosts with local mailboxes output a message, like You have mail, if messages are waiting as you log in. If your host doesn't, you can do it by adding a call to msgchk in your shell setup file (.login, .profile). To suppress the message when there's no mail, save the msgchk output in a shell variable and test the exit status. A non-zero status means that there were no messages -- or some other problem. The next Example shows how:

Example: Automatic mail check in shell setup file

Bourne and Korn shells:

if msgs=`msgchk`
then echo "$msgs"
fi

C shell:

set msgs=(`msgchk`)
if ($status == 0) echo "$msgs"
mgschk also works across a network with POP; the Section Using MH with POP has basic information.

[Table of Contents] [Index] [Previous: More About scan] [Next: Other Features of inc]


Last change $Date: 1996/06/06 15:09:13 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jpeek@jpeek.com>