#!/bin/bash # trimmailbox - A simple script to ensure that only the four most recent # messages remain in the user's mailbox. Works with Berkeley Mail # (aka Mailx or mail): will need modifications for other mailers! setglobal keep = '4' # by default, let's just keep around the four most recent messages setglobal totalmsgs = $[echo 'x' | mail | sed -n '2p' | awk '{print $2}] if test $totalmsgs -lt $keep { exit 0 # nothing to do } setglobal topmsg = "$shExpr(' $totalmsgs - $keep ')" mail > /dev/null << """ d1-$topmsg q """ exit 0