I'm trying to modify the You have new mail message that is shown below MOTD when you login via SSH. My goal is to make that message more visible (bright color would be great) so it gets my attention when I log in.

  • 1
    I took a quick look at Bash source code and it seems it's not possible to customize. The message is hardcoded in mailcheck.c.. But you can always recompile Bash. – Arkadiusz Drabczyk Feb 23 at 0:19
  • @ArkadiuszDrabczyk look harder – Uncle Billy Feb 23 at 1:06

In Bash, custom messages can be set with MAILPATH. The man page has this example:

MAILPATH='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has mail!"'

Trying it:

$ export MAILPATH="$MAIL?\"Santa was here.\""
"Santa was here."

Oh, uh, okay. Must have misread the man page there.

bright color would be great

So we have to smuggle us some color escape codes into the message...

$ esc=$'\e'
$ export MAILPATH="$MAIL?$esc[1;37;44mREAD YOUR MAIL RIGHT NOW$esc[0m"
$ echo $MAILPATH
/var/spool/mail/frostschutz?READ YOUR MAIL RIGHT NOW

I don't know how to color things here, just imagine it screaming in bright white blue. Color choices are subject to taste and local terminal color scheme settings.

Also check that MAILPATH was not already in use and MAIL actually has the correct path to use for MAILPATH.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.