#!/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! setvar keep = '4' # by default, let's just keep around the four most recent messages setvar totalmsgs = "$(echo 'x' | mail | sed -n '2p' | awk '{print $2}')" if test $totalmsgs -lt $keep { exit 0 # nothing to do } setvar topmsg = """$(( $totalmsgs - $keep ))" mail > /dev/null <<< """ d1-$topmsg q """ exit 0