Checking for Mail Waiting: msgchk

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.