This question already has an answer here:

Whats the difference between mail and mailx?

I'm trying to troubleshoot a problem where I can send mail from server A with this echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS command but executing the same command from server B throws me this error (Both servers are RHEL)

mail: invalid option -- r
Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...
            [-- sendmail-options ...]
       mail [-iInNv] -f [name]
       mail [-iInNv] [-u user]

Now... going through mail manpages to ty to understand whats happening, man mail gives me this:

In Server A

MAILX(1)                         User Commands                        MAILX(1)

       mailx - send and receive Internet mail

       mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops]
              [-A account] [-S variable[=value]] to-addr . . .
       mailx [-BDdeEHiInNRv~] [-T name] [-A account] [-S variable[=value]] -f [name]
       mailx [-BDdeEinNRv~] [-A account] [-S variable[=value]] [-u user]

But in server B

MAIL(1)                   BSD General Commands Manual                  MAIL(1)

     mail - send and receive mail

     mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr... [-- sendmail-options...]
     mail [-iInNv] -f [name]
     mail [-iInNv] [-u user]

Now... if I try man mailx in server B I get:

MAILX(P)                   POSIX Programmerâs Manual                  MAILX(P)

       This manual page is part of the POSIX Programmerâs Manual.  The Linux implementation of this interface may differ
       (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not  be  imple-
       mented on Linux.

       mailx - process messages

   Send Mode
              mailx [-s subject] address...

   Receive Mode
              mailx -e

              mailx [-HiNn][-F][-u user]

              mailx -f[-HiNn][-F][file]

Server B has a different version of mail than Server A? Mailx and Mail are different things? I would like to use the -r option I use in server A but in server B and I don't really know whats happening.

marked as duplicate by Gilles, jasonwryan, slm, Mat, phunehehe Sep 6 '13 at 6:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from serverfault.com Sep 5 '13 at 13:10

This question came from our site for system and network administrators.


Behold the confusing history of mail, nail, mailx.

Briefly, mail is the older program, mailx (formerly nail in some implementations) is a newer version , with an extended mostly-but-not-totally-compatible interface.

mailx is still quite old, created around 1986 and standarized as part of POSIX in 1992. There are several implementations (even in modern Linuxes), and some provide extensions to the standard.

The -r option is one such extension. Depending on your Linux distribution, and the mail package you have installed, you might or not have that option. See eg here.

If you want to write portable scripts, it's better not to rely on it.

  • And let us not forget Mail in HP-UX systems. – adamo Sep 5 '13 at 13:18

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