Format
mailx [–efHiNn]
[–u user] [filename]
mailx [–FinU]
[–h number] [–r address]
[–s subject] user …
Description
mailx helps
you read electronic mail messages. It can also send messages to users
on your system, but it has no built-in facilities for sending messages
to other systems.
The command line:
mailx [options] user user user …
sends
a mail message to the given users. If you do not specify any users
on the command line,
mailx lets you read
incoming mail interactively. For more information, see
sendmail.
In
a double-byte locale, aliases, variables, and addresses can contain
double-byte characters.
This description of
mailx is
divided into several sections:
- Options
- General overview
- Command-mode subcommands
- Input-mode subcommands
- Startup files
- Examples
- Environment variables
- Files
- Exit values
- Portability
- Related information
Options
You can use the following options
when reading messages:
- –e
- Checks to see if you have any messages waiting to be read. With
this option, nothing is displayed. If you have waiting messages, mailx exits
with a successful status return; otherwise, mailx exits
with a failure return.
- –f filename
- Looks for messages in the specified file instead of in your current
mailbox. If you do not specify filename, mailx reads
messages from $HOME/mbox.
- –H
- Displays only the header summary of a message.
- –N
- Does not display the header summary of messages.
- –u user
- Looks for messages in the system mailbox of the specified user.
This works only if you have read permission on the user's system mailbox.
You can use the following options only when
sending messages:
- –F
- Records your message in a file with the same name as the first
user specified on the command line. This option overrides the record variable,
if it has been set.
- –h number
- Indicates how many “hops” a message has already made from one
machine to another (in a network of machines). This option is not
intended for most users; network mail software uses the option to
prevent infinite loops (the same message cycling through a sequence
of machines without ever getting to its intended destination).
- –r address
- Passes the given address to network mail software. If this option
is present, it disables all input mode commands. Again, this option
is not intended for most users.
- –s subject
- Uses the given subject string in the Subject heading
line of the message. If the subject contains spaces or tab characters,
the string should be enclosed in double quotation marks or single
quotation marks. If you specify this option on the command line, mailx does
not prompt you to enter a subject line when you type in the text of
the message. The subject accepts at most LINE_MAX-10(2038) bytes.
Any subjects longer than that will be truncated at 2038.
- –U
- Converts the address from UNIX-to-UNIX Copy Program (UUCP) style
to Internet Protocol standards. This option overrides the effect of
the conv variable.
This option
is not supported.
You can use these options
for both sending
and reading messages: - –i
- Ignores interrupts (for example, from pressing <Break> or <Ctrl-c>).
- –n
- Does not initialize your mailx session
from the system's /etc/mailx.rc file.
General overview
This section describes
the default behavior of mailx.
The
simplest command to send a message is:
mailx address address address …
where each
address names someone who is
to receive the message. The simplest kind of address is the
login
name of someone else who uses your shell.
You can also
send messages as input to commands. To do this, use an address that
consists of a pipe symbol (
|) followed by a command
line that invokes the appropriate command; enclose this whole address
in single quotation marks. For example:
mailx ROBIN '|cat >save'
mails
a message to
ROBIN and also copies the message into
a file called
save.
After you type in the command to
send a message, mailx asks you to enter
the subject of the message (a brief description of what the message
is about), and then lets you type in the text of the message. This
brief description can be up to 256 characters long. Your message can
consist of any number of lines, and may include blank lines. When
you finish entering the message, type a line consisting only of a
tilde (~), followed by a period (.); then press the
enter key. This tells mailx that the message
is ready to be sent.
mailx puts the
completed message into a file called the recipient's system mailbox.
The message stays in the system mailbox until the recipient asks to
read the message. At that point, the message is obtained from the
system mailbox and displayed on the recipient's workstation. The message
is then saved in the recipient's personal mailbox. Since this is typically
a file named mbox in the recipient's home
directory, we use the name mbox to represent the personal mailbox
and mailbox for a system mailbox.
The simplest way to
read incoming messages is to type the command mailx (with
no addresses on the command line). This starts an interactive session in
which mailx lets you read your mail and
perform other operations. For example, you can display new messages,
delete old ones, reply to messages, or forward them to someone else,
and so on. When you are performing operations in this way, you are
in command mode. When
you are typing in the text of a message, you are in input mode.
A
message consists of a sequence of
header lines, followed
by the body of the message. The header lines tell who sent the message,
the time and date that the message was sent, the subject of the message,
and so on.
mailx automatically creates header
lines. Some of the common header lines are:
- Cc: name name …
- Stands for “carbon copies”. This indicates that copies of this
message are to be sent to the specified recipients. The names of these
recipients appear in the header lines of everyone receiving the message.
- Bcc: name name …
- Stands for “blind carbon copies”. This
is similar to Cc:, but the names of people receiving
carbon copies do not appear in the header lines of the message. Recipients
do not know that these people received a copy of the message.
- Subject: text
- Gives the subject of the message.
- To: name name …
- Gives the names of people who were sent the message directly.
All messages are in one of the following states:
- deleted
- You used a delete, dp,
or dt command to delete the message. When mailx quits,
messages in this state are deleted.
- new
- The message is in the system mailbox and you have not yet read
it or otherwise changed its state. When mailx quits,
messages in this state are kept in your system mailbox.
- preserved
- You used a preserve command on the message.
When mailx quits, messages in this state
are kept in their current locations.
- read
- You used one of the following commands on the message:
~F copy Print type
~f mbox print undelete
~M next top
~m pipe Type
or you used delete
, dp, or dt on
the preceding message and the autoprint variable was set. When mailx quits
and you are in your system mailbox, read messages
are kept in your personal mailbox—unless the hold variable
is set, in which case, read messages
are kept in your system mailbox. If you are in your personal or a
secondary mailbox when mailx quits, read messages
are kept in their current location.
- saved
- You used a save or write command
on the message. If the current mailbox is the system mailbox and the
variable keepsave was set, messages in the
state saved are saved to the mbox. If the
current mailbox is the system mailbox and you used a quit or file command
to exit the current mailbox, messages in the state saved are deleted
from the current mailbox.
- unread
- You have run more than one mailx session
with the message in the system mailbox and you have not read it or
otherwise changed its state. When mailx quits,
messages in this state are kept in your system mailbox.
Command-mode subcommands
The
standard format of a command-mode subcommand is:
[subcommand][refs][arguments]
If no
subcommand is specified, the default
subcommand depends
on the setting of the
_UNIX03 variable:
- If the variable _UNIX03=YES is set,
then n[ext] is assumed.
- If the variable _UNIX03 is unset or
is not set to YES, then p[rint] is
assumed.
The
refs argument indicates
the messages to which you want to apply the
subcommand.
mailx numbers
incoming messages sequentially as they are received. The easiest way
to refer to a message is to give its number. For example, the subcommand:
p 3
displays message number 3. At any point
in a
mailx session, there is one message
that is considered the
current message. This is the message you most recently did
something with (for example, the one you most recently read). If you
omit the
refs argument in a subcommand that
uses
refs, the subcommand works with the
current message.
You can also use special notations as the
refs value:
- refs
- Meaning
- n
- Message number n
- n-m
- Messages n through m
- .
- The current message
- ^
- The first undeleted message (or first deleted message for undelete)
- $
- The last message
- +
- Next message
- -
- Previous message
- *
- All messages
- user
- All messages from the given user
- /string
- All messages with string in the subject line
(the case of characters in string is ignored)
- :d
- All deleted messages
- :n
- All new messages
- :o
- All old messages
- :r
- All messages that have already been read
- :u
- All unread messages
Several
refs arguments
may be specified for the same subcommand, separated by spaces. For
example:
p alice lewis
displays all messages
from
alice plus all messages from
lewis.
The
arguments allowed at the end of a command-mode subcommand depend on
the subcommand itself. If a subcommand allows a file name as an argument,
you can use the usual file name generation characters in the file
name (see sh).
File
names, where expected, are subjected to the following transformation,
in sequence:
- If the file name begins with an unquoted plus sign, and the folder variable
is defined, the plus sign will be replaced by the value of the folder variable
followed by a slash. If the folder variable
is unset or set to null, the file name will be unchanged.
- Shell word expansions will be applied to the file name. If more
than one path name results from this expansion and the command is
expecting one file, the multiple path names will be combined into
one argument.
The following list shows
the subcommands recognized in command mode. In every subcommand name,
some characters are enclosed in square brackets. These characters
are optional. For example, the
p[
rint]
command may be given as
p,
pr,
pri,
prin or
print.
- a[lias] [alias [name …]]
- Sets up an address alias. If you enter
a subcommand to send mail to the given alias,
the messages are sent to the given list of names. For example, you
might enter the subcommand:
alias joe JSMITH
From this point onward, you can address messages to joe and
they are sent to jsmith. You may also set up an alias
for several people, as in: alias choir SOPRANO ALTO TENOR BASS
After you have done this, you can send messages to choir and
they are sent to the names that follow choir in the
command. Alias substitution only
takes place when alias is used as the whole
mail address. Alias substitution doesn't take place when replying
to a message that has an alias match in
the addresses.
If you use only one argument,
alias lists
the value of that alias. For example,
alias joe would
display
jsmith. Entering the
alias subcommand
without any arguments displays a list of the currently defined aliases.
Note: Aliases entered interactively remain in effect only until the
end of the current interactive session. To make an alias permanent,
include the
alias subcommand in your startup
file (see
Startup files). See also
group.
- alt[ernates] name
- Lists a set of alternate names for your own login name. This is
useful for people who login under several different names. When you
reply to a message, mailx typically sends
your reply to the author of the message and all the recipients as
well; however, it does not send the message to any of your alternate
login names. You don't have to worry about sending mail to yourself.
Specifying alternates without names displays your list of currently
defined alternate names.
- cd directory
- Makes directory your new working directory.
If no directory is specified, cd goes
to your HOME directory.
- ch[dir] directory
- Is the same as cd.
- c[opy] [refs]
[filename]
- Copies the messages referred to by refs into
the given file. The filename must be specified.
If the file does not already exist, it is created.
If no refs are
specified, the current message is saved. If no filename is
specified, your mbox is saved.
This
operation does not mark the message as saved; if it was previously
unread, it is still regarded as an unread message. Thus, the original
message remains in your system mailbox. See also save.
- C[opy] [refs]
- Is similar to the copy command, except
that the messages referred to are saved in a file the name of which
is derived from the author of the first message referred to. The name
of the file is the author's name, stripped of any network addressing.
If the folder variable is set, the
file is saved to the specified directory. The copied messages are
not marked as “saved”. If refs is not specified,
the current message is copied.
- d[elete] [refs]
- Deletes the specified messages from your system mailbox.
If refs is not specified, the current message
is deleted. After a delete operation, the current message is set to
the message after the last message deleted. Deleted messages are not
thrown away until you end your session with the current mailbox (see quit and file).
Until then, they can be undeleted (see undelete).
- di[scard] [header…]
- Does not display the given header fields
when displaying a message. For example:
discard References
tells mailx not to display the References line
at the beginning of any mail message. These header lines are retained
when the message is saved; they are just not shown when the message
is displayed. See also ignore and retain.
- dp [refs]
- Deletes the specified messages and then displays the message after
the last message deleted. If there is no subsequent message, mailx displays
its command prompt.
- dt [refs]
- Is the same as the dp subcommand.
- ec[ho] string …
- Echoes the given strings (like the echo subcommand).
- e[dit] [refs]
- Lets you edit the messages specified by refs.
The messages are stored in a temporary file and an editor is invoked
to let you edit the file. The default editor is ed,
but you can change this using the EDITOR environment variable.
- ex[it]
- Quits mailx without changing the system mailbox.
Contrast this with quit, which ordinarily
removes from the system mailbox those messages you've read, saved,
or deleted.
- fi[le] [filename]
- Quits the system mailbox (as if a q[uit]
subcommand were run) and then reads in the specified file as the new
mailbox to examine. If no file name is specified, the default is your
current mailbox.
Several special strings can be used in place
of
filename:
- %
- Your system mailbox.
- %user
- The system mailbox for user
- #
- The previous file
- &
- Your mbox (personal mailbox)
- +file
- The named file in the folder directory
- fold[er] [filename]
- Is the same as the file subcommand.
- folders
- Displays the names of the files in the directory given by the folder variable.
See Environment variables.
- F[ollowup] [refs]
- Replies to the first message given in refs; mailx sends
this reply to the authors of every message given in refs.
The Subject line is taken from the first message
in refs. Your reply is automatically saved
in a file which derives its name from the author of the message to
which you are replying.
- If the variable _UNIX03=YES is set,
then the command overrides the record variable
if record is set.
- If the variable _UNIX03 is unset or
is not set to YES, then the command does
not override the record variable.
To create your reply, mailx puts
you into input mode, where you can use all of the input mode commands.
- fo[llowup] [ref]
- Replies to the specified message; if no message ref is
given, you reply to the current message. Your reply is automatically
saved in a file which derives its name from the author of the message
to which you are replying. This overrides the record environment
variable if record is
set.
To create your reply, mailx puts
you into input mode, where you can use all of the input mode commands.
- f[rom] [refs]
- Displays the header summary for the specified messages. If refs is
not given, the current message is used.
- g[roup] [alias [name …]]
- Is the same as the alias command.
- h[eaders] [ref]
- Displays the headers of a screenful of messages surrounding the
message given by ref. The number of lines
in a screen is given by the screen variable. If no ref is
specified, the current message doesn't change; otherwise the current
message is changed to the message specified by ref.
- hel[p]
- Displays a summary of the command-mode subcommands.
- ho[ld] [refs]
- Retains the specified messages in your system mailbox. For example,
you might decide to hold a message if you
read it, but decide not to act upon it immediately. If refs is
not specified, the current message is held. If any of the specified
messages have been marked as deleted, the hold subcommand
overrides that and still retains the messages. Subsequent delete, dp,
and dt commands during the same mailx session
can delete files marked for retention. See also preserve and
the variables hold and keepsave.
- i[f] code mailx
subcommands | [el[se] mailx
subcommands] | [en[dif]]
- Is primarily intended for use in startup files. The code must
be the character r or s. If it is r,
the first set of mailx subcommands are executed if mailx is
in receive mode, and the second set if mailx is
in send mode. If code is s,
the opposite is true. The else part is optional. See Startup files.
- ig[nore] [header …]
- Is the same as the discard subcommand.
- l[ist]
- Displays the names of all command-mode subcommands.
- m[ail] address …
- Sends a message to the specified recipients. mailx goes
into input mode to let you enter the text of the message.
- mb[ox] [refs]
- Indicates that the given messages are to be saved in your mbox (personal
mailbox) when mailx quits normally (that
is, through the quit command as opposed
to exit).
- n[ext] [refs]
- Goes to the next message in the mailbox that appears in the list
of refs. For example:
n user
goes to the next message from the specified user.
- pi[pe] [[refs] command]
- Pipes the messages given by refs through
the specified shell command. These messages
are considered read. If refs is not specified,
the current message is used. If no command is
specified, mailx uses the command specified
by the cmd variable. See Environment variables. If the page variable has a value, a
form feed character is sent into the pipe after every message.
The
subcommand | [refs] [command]
is equivalent to pipe.
- pre[serve] [refs]
- Is the same as the hold subcommand.
- P[rint] [refs]
- Displays the specified messages on the screen. If refs is
not specified, the current message is displayed. All header fields
are displayed; the discard, ignore and retain subcommands
do not affect Print. If the crt variable
is set to an integer, messages with more lines than that integer are
"paginated" using the command specified by the PAGER variable.
- p[rint] [refs]
- Displays the specified messages on the screen. If refs is
not specified, the current message is displayed. Header fields specified
by discard, ignore and retain subcommands
affect print. If the crt variable
is set to an integer, messages with more lines
than that integer are “paginated” using the command specified by the PAGER variable. For
more information, see Environment variables.
- q[uit]
- Ends a mailx session. This is the usual
method to leave mailx. Messages that have
been read but not saved or deleted are stored in your mbox (personal
mailbox). Messages that are still unread are retained in your system
mailbox. Messages that have been deleted or explicitly saved in other
files are discarded. Typing the end-of-file character has the same
effect.
- R[eply] [refs]
- Sends a reply to the authors of each of the messages specified
by refs. If refs is
not specified, the current message is used. The Subject line
of the reply message is taken from the first message in refs.
If the record environment variable is set to a file name, your
reply message is appended to the end of that file.
Normally, you
use Reply if you just want to send your
reply to the author of a message, and reply if
you want to send your reply to the author and all recipients. If set,
the flipr environment variable reverses the
meanings of the R and r commands.
See Environment variables.
- r[eply] [ref]
- Sends a reply to the author of a specific message, and all other
recipients of the message. If ref is not
specified, mailx replies to the current
message. If the record environment variable is set to a file
name, your reply message is appended to the end of that file.
- R[espond] [refs]
- Is the same as the Reply subcommand.
- r[espond] [ref]
- Is the same as the reply subcommand.
- ret[ain] [header …]
- Is the opposite of the discard subcommand.
It tells mailx to display the given header fields
when displaying a message. The comparison of header fields
is not case sensitive. You can use retain to
override existing discard and ignore commands.
If you do not specify any header fields, retain displays
a list of currently retained header fields.
- S[ave] [refs]
- Saves the specified messages in a file the name of which is taken
from the author of the first message (the file name is the author's
name, without any attached network addressing). If the folder variable
is set, the file is saved to the specified
directory.
- s[ave] [refs][filename]
- Saves the specified messages in the given file. If refs is
not given, the current message is added to the mbox. (The value
of the append variable determines whether the
message is added to the beginning or the end of the mbox).
The file is created if it does not already exist. If you do not specify filename, mailx saves
the messages in mbox (your personal mailbox). A message that
has been saved with save is normally deleted
from mailbox when mailx ends
(see quit); but see the variables hold and keepsave.
- se[t] name
- Defines a variable with the given name and
assigns it a null value. If you omit name, set displays
a list of all defined variables and their values.
- se[t] name=value
- Defines a variable with the given name and
assigns it the given value, which may be
a string or a number.
- se[t] noname
- Is the same as the unset name subcommand.
- sh[ell]
- Invokes the shell given by the SHELL environment
variable.
- si[ze] [refs]
- Displays the size in bytes of each of the specified messages.
If no refs are specified, the current message
is used.
- so[urce] file
- Reads the specified text file, executes
its contents as command-mode subcommands, and then returns to read
more commands from the original source.
- to[p] [refs]
- Displays the first few lines of each of the specified messages.
If refs is not specified, the current message
is used. If the toplines variable has a numeric value, that
many lines are displayed from each message; otherwise, five lines
are displayed from each message.
- tou[ch] [refs]
- “Touches” the specified messages, making them appear to have been
read. This means that when you quit mailx,
the messages are saved in your mbox (personal mailbox) if they
are not deleted or explicitly saved in another file. If refs is
not specified, the current message is touched.
- T[ype] [refs]
- Is the same as the Print subcommand.
- t[ype] [refs]
- Is the same as the print command.
- una[lias] [alias[name …]]
- Deletes specified alias names.
- u[ndelete] [refs]
- Restores previously deleted messages. When messages are deleted,
they are not discarded immediately; they are just marked for deletion
and are deleted when mailx ends. Until mailx ends,
you can use undelete to restore the specified
messages. You cannot undelete messages deleted
in previous sessions. If you do not specify refs,
this command restores the first deleted (but not yet undeleted) message
following the current message; if no such message exists, it restores
the last deleted (but not yet undeleted) message preceding the current
message. If the autoprint variable is set, the last restored
message is displayed. This is the only subcommand that lets you give
a ref to a message that has been deleted.
- U[nread] [refs]
- Marks the specified messages as unread.
- uns[et] name …
- Discards the specified variables.
- ve[rsion]
- Displays version information about mailx.
- v[isual] [refs]
- Edits the specified messages with a screen editor. If refs is
not specified, the current message is edited. The messages are saved
in a temporary file and the screen editor is invoked to edit that
file. The editor used is given by the VISUAL variable. See Environment variables.
- w[rite] [refs] filename
- Writes the specified messages into the given file. If refs is
not specified, the current message is written. write is
the same as save, except that it does not
write out the header lines and the blank line at the end of the message.
- x[it]
- Is the same as the exit command.
- z[+|-]
- Scrolls the header display forward (if z or z+ is
specified) or backward (if z- is specified)
one screenful.
- ! command
- Executes the given shell command. For
example:
!lc
lists all files in the current
directory. The shell that will be used to run the command is given
by the SHELL environment variable. See Environment variables.
- #comment
- Specifies that mailx should ignore everything
from the # to the end of the line. This
is useful for putting comments into startup files.
- ?
- Is the same as the help command (it
displays a summary of the command-mode subcommands).
- =
- Displays the current message number.
Input-mode subcommands
You can use input-mode
subcommands when entering the text of a message. You must type mode
subcommands at the beginning of an input line; you cannot type them
in the middle of a line. By default, each input-mode subcommand begins
with the tilde (~) character, called the
escape character. You
can use the
escape variable to change the
escape character, but in the documentation that follows, we always
use tilde.
- ~.
- Marks the end of input in a mail message.
- ~?
- Displays a summary of the input-mode subcommands.
- ~A
- Inserts the autograph string at this point in the message. This
autograph string is given by the Sign variable.
- ~a
- Is similar to ~A, except that it uses the variable sign.
- ~b name …
- Adds the specified names to the blind carbon copy list.
- ~c name …
- Adds the specified names to the carbon copy list.
- ~d
- Reads in the dead.letter file.
- ~e
- Invokes an editor on the message that you have composed. The editor variable
determines the editor that is invoked.
- ~F [refs]
- Forwards the given messages. The text of the messages is inserted
at this point in the message you are composing. The message headers
are also inserted with all header fields regardless of the discard, ignore,
and retain subcommands. This is valid only
when you entered mailx in command mode and
then went into input mode to compose a message.
- ~f [refs]
- Is similar to ~F except that the header fields included are determined
by the discard, ignore,
and retain subcommands.
- ~h
- Prompts you to enter the following header lines:
Subject Cc Bcc To
For
some of these, mailx displays an initial
value for the header. You can edit this initial value as if you had
just typed it in yourself, using backspaces and line deletes.
- ~i name
- Inserts the value of the named variable followed by a newline
at this point in the message.
- ~M [refs]
- Inserts the text of the specified messages at this point in the
message. If refs is not specified, the current
message is used. Messages inserted in this way have each line prefixed
with the value of the indentprefix variable. The
message headers are also inserted with all header fields included
regardless of the discard, ignore,
and retain subcommands. This is valid only
when you entered mailx in command mode and
then went into input mode to reply to a message.
- ~m [refs]
- Is similar to ~M, except that the header fields are determined
by the discard, ignore,
and retain subcommands.
- ~p
- Displays the message being composed.
- ~q
- Quits input mode as if you had interrupted the message. If you
have already composed part of a message, the partial message is saved
in the dead.letter file; the description of the dead environment
variable has more information..
- ~r filename
- Reads in the contents of the specified file and adds that text
at this point in the message.
- ~s text
- Sets the Subject line to the given text.
- ~t address address …
- Adds the given addresses to the To: list (people
who will receive the message).
- ~v
- Invokes a screen (visual) editor on the message that you have
composed. The VISUAL variable determines the editor that is
invoked.
- ~w file
- Writes the current text of your message to the specified file.
The header lines for the message are not written.
- ~x
- Quits in the same way as ~q, except that the message is not saved
in the dead.letter file.
- ~< filename
- Is the same as the ~r command.
- ~< !command
- Runs the given shell command and adds
the standard output of that command at this point in the message.
For example, your message might contain:
My program is giving me this odd output:
~< !prog
What do you think is causing it?
- ~: mail_command
- Runs the given command-mode mail_command.
This is valid only when you entered mailx in
command mode and then went into input mode to compose a message.
- ~_ mail_command
- Is the same as the ~: command.
- ~! command
- Runs the given shell command. For example,
you can use:
>~! ls
to get a list of files
in the working directory. The shell that is invoked to run the command
is given by the SHELL environment variable. If the bang variable
is set, mailx replaces each unescaped exclamation
mark (!) in command with the command run
by the previous command or ~! command escape.
- ~ command
- Pipes the current message through the specified shell command.
If the command ends with a successful exit
status, the output of the command replaces the text of the current
message. For example:
~|fmt
fills and justifies
the lines of your message and replaces the message with the formatted
message. ~| uses the shell given by the SHELL environment variable
to run command.
Startup files
When you run
mailx in
command mode,
mailx does the following:
- Sets all variables to their default values. mailx processes
command-line options, using them to override any corresponding default
values.
- Imports appropriate external environment variables, using them
to override any corresponding default values.
- Reads commands from the system startup file, /etc/mailx.rc. This sets up
variable values and definitions that should be common to all users.
If you do not want mailx to read the system
startup file, use the –n option on the mailx command
line.
- After reading and processing the system startup file, mailx does
the same with a personal startup file, which is MAILRC by default. This is a file in your HOME directory.
The name of the file is .mailrc.
Startup files typically set up display options and define
aliases. However, any command is valid in a startup file except for
the following:
- Copy
- edit
- followup
- Followup
- hold
- mail
- preserve
- reply
- Reply
- respond
- Respond
- shell
- visual
- !
If a line in a startup file contains an error or an incorrect
command, the rest of the startup file is ignored. mailx ignores
blank lines in a startup file.
Examples
The
following example composes and sends a message to several users. Items
shown in bold are output by mailx.
mailx JEAN
Subject: Greetings
This is just a short note to say hello.
~c JUAN JOHN JOHANN
~.
On the first line, the message is just addressed
to jean. The ~c line adds more people who
will receive copies of the message.
Environment variables
A large
number of variables are used to control the behavior of mailx.
These environment variables are divided into two classes: those that
always come from the external environment, and those that may be set
up in either the external environment or within a mailx session.
The
following variables always come from the external environment; they
can be changed inside a
mailx session, except
where marked.
- DEAD
- Gives the name of a file that can be used as the dead.letter file.
Partial messages are saved in this file if an interrupt or error occurs
during creation of the message or delivery. By default, the name of
this file is $HOME/dead.letter.
- EDITOR
- Gives a command, possibly with options, that is run when using
the command mode edit or the input mode ~e.
The default is ed (see ed — Use the ed line-oriented text editor for
more information about ed).
- HOME
- Gives the
name of your home directory. This cannot be changed inside mailx .
- LISTER
- Gives a command, possibly with options, that mailx invokes
when displaying the content of the folder directory
for the folders subcommand. If this variable
is null or unset, mailx uses ls.
By default, this variable is unset.
- LOGNAME
- Gives your login name.
- MAIL
- Gives the
path name of the user's mailbox file for purposes of incoming mail
notification.
- MAILDIR
- Gives the
name of the directory where system mailboxes are stored. If this is
not set, the default is /usr/mail. The actual name of a user's
system mailbox is derived in a system-dependent way by combining MAILDIR and
the user's login name. For mailx to work
properly, the MAILDIR directory must exist.
- MAILRC
- Gives the name of your startup file. This cannot
be changed inside mailx. By default, MAILRC has
the value $HOME/.mailrc. For more information
about startup files, see Startup files.
- MBOX
- Gives the name of your mbox (personal mailbox) file. Messages
that have been read but not saved elsewhere are saved here when you
run quit (but not when you run exit).
The default is $HOME/mbox.
- PAGER
- Gives a command, possibly including options. mailx sends
display output through this command if the output is longer than the
screen length given by crt. The default
value is more (see more — Display files on a page-by-page basis for more information
about more).
- SHELL
- Gives a command, possibly with options. mailx assumes
that this command is a command interpreter. mailx invokes
this command interpreter whenever it is asked to run a system command
(for example, through the ! command-mode command). The default is sh (see sh — Invoke a shell for more information about sh).
- TERM
- Contains the name of the terminal type. This cannot be changed
inside mailx.
- TZ
- This variable may determine the time zone used to calculate date
and time strings written in mailx. This
cannot be changed inside mailx .
- _UNIX03
- For more information about the effect of _UNIX03 on this command,
see Shell commands changed for UNIX03.
- VISUAL
- Gives a command, possibly with options, that mailx invokes
when using the command-mode visual subcommand
or the input mode ~v subcommand. The default
is vi (see vi — Use the display-oriented interactive text editor for
more information about vi).
The HOME and LOGNAME variables must be set
before you enter
mailx. Otherwise,
mailx will
not work properly. The TZ variables can only be set before you enter
mailx.
If not set or set to null, a default time zone ("UTC0") will be used.
These variables are typically set during shell login. (You can login
with the
OMVS TSO/E command,
telnet,
rlogin,
or
ssh.) If you do not log in, you must
set the variables in some other way, using the commands:
export LOGNAME=name
export HOME=directory
The
remaining variables can be set in the external environment or in the
course of a mailx session. You can set or
change the value of a variable with the set subcommand;
you can discard a variable with the unset subcommand.
You may find it convenient to create a startup file that sets these
variables according to your preferences; this eliminates the need
to set variables each time you enter mailx.
Many
of the following variables represent on-off options. If you set the
variable itself (to any value), the option is turned on. To turn the
option off, you can unset the variable, or set a variable consisting
of
no followed by the name of the original
variable. For example, setting
autoprint turns the autoprint
option on, and setting
noautoprint turns it off.
- allnet
- Assumes that
network addresses with the same login component refer to the same
person. Network addresses typically consist of several components,
giving information that lets a mail server identify a machine on the
network, a route to that machine, and the login name of a user on
that machine. mailx assumes that the login
name is the last component. For example:
print name
displays
all messages that originated from the same login name,
regardless of the rest of the network address. The default is noallnet,
where different addresses are assumed to be different users, even
if the login name components are the same.
- append
- Appends messages
to the end of the mbox file (your personal mailbox) after termination.
The default is noappend; messages are placed at the beginning
of the mbox file instead of the end.
- ask
- Prompts you
for a Subject: line when composing a message (if
you have not already specified one with the –s option).
This option is on by default; to turn it off, set noask. ask is
the same as asksub. noask is the same as noasksub.
- askbcc
- Prompts you
for a Bcc: list when composing a message. The default
is noaskbcc; you are not prompted.
- askcc
- Prompts you
for a Cc: list when composing a message. The default
is noaskcc; you are not prompted.
- asksub
- Prompts you
for a Subject: line when composing a message (if
you have not already specified one with the –s option).
This option is turned on by default; to turn it off, set noasksub. asksub is
the same as ask. noasksub is the same as noask.
- autoprint
- Automatically
displays the last message deleted with the delete subcommand
or the last message undeleted with undelete.
The default is noautoprint; you are not shown messages that
you delete or undelete.
- bang
- Records shell
commands run inside the mailx session (for
example, through the ~! input-mode command). Then, if you
issue a shell command and the shell command contains a ! character, mailx replaces
that character with the command line for the previous shell command.
The default is nobang, in which case a ! in
a shell command line is not treated specially.
- cmd
- Contains a
command, possibly with options. This specifies a default command line
to be used for the command-mode pipe subcommand.
For example:
set cmd="cat"
pipes messages
through cat when the pipe subcommand
is invoked. The default is nocmd.
- crt
- Contains an
integer number. If a message has more than this number of lines, the
message is piped through the command given by the PAGER variable,
whenever the message is displayed. crt is not set; the default
is nocrt.
- debug
- Enables verbose diagnostics for debugging. Messages are not delivered.
The default is nodebug.
- dot
- Accepts a
line consisting only of a dot (.) to indicate the
end of a message in input mode. Thus . is equivalent
to ~.. The default is nodot. If ignoreeof is set, mailx ignores
a setting of nodot; the period is the only way to end input
mode.
- escape
- Gives the
character used to begin input-mode subcommands. The default is the
tilde (~). If this variable is unset, tilde is used as the escaping
character. If this variable is set to null, mailx disables
command escaping.
- flipr
- Reverses the
meanings of the R and r subcommands.
The default is noflipr. See also Replyall.
- folder
- Contains the
name of a directory in which mailx saves
mail files, if you use a plus sign + in front of
the filename. This lets you specify a standard directory for saving
mail files. Whenever you specify a filename for a mailx command,
putting a plus sign (+) in front of the name specifies
that the file is to be accessed or stored in the folder directory.
If the value of folder begins with a slash, it is taken
as an absolute path name; otherwise, mailx assumes
that the directory is directly under your HOME directory. The default
is nofolder. If you want to use + in
file names that appear on the mailx command
line itself (as opposed to commands in a mailx session),
you must make folder an exported shell environment variable.
- header
- Displays a
summary of message headers at the beginning of a mailx command-mode
session. This is the default.
- hold
- Keeps all
messages in your system mailbox instead of saving them in your personal mbox.
The default is nohold.
- ignore
- Ignores interrupts
received while composing a message. The default is noignore.
- ignoreeof
- Ignores end-of-file
markers found while entering a message. The message can be ended by
“.” or ~. on a line by itself. The
default is noignoreeof.
- indent
- Contains a
string that mailx uses as a prefix to each
line in messages that ~m and ~M insert. The default is
one tab character.
- indentprefix
- As
with indent, contains a string that mailx uses
as a prefix to each line in messages that ~m and ~M insert. The
default is one tab character. If both indent and indentprefix are
set, indentprefix takes precedence.
- keep
- Does not remove
your system mailbox if the mailbox contains no messages. The mailbox
is truncated to zero length—that is, it is merely emptied, although
it still exists. If the default nokeep is in effect, empty
mailboxes are removed.
- keepsave
- Keeps messages
in your system mailbox even if they have been saved in other files.
The default, nokeepsave, deletes messages from the system mailbox
if they have been saved elsewhere.
- mailserv
- Identifies
the mail server being used for remote mail.
- metoo
- When replying
to a message with your login name in the recipient list, sends a reply
to all other recipients, the author, and you. If nometoo is
set, you are not to be sent the reply. The default is nometoo.
- onehop
- Attempts to
send replies directly to the recipients instead of going through the
original author's machine. When you reply to a message, your reply
is sent to the author and to all recipients of the message. On a network, mailx normally
specifies the recipient addresses so that all the replies go to the
original author's machine first, and then on to the other recipients.
The default is noonehop.
- outfolder
- Causes files
used to record outgoing messages (see the description of record)
to be located in the directory given by folder unless folder contains
an absolute path name.
The default is nooutfolder.
- page
- Tells the pipe subcommand
to insert a form-feed character after each message that it sends through
the pipe. The default is nopage.
- prompt
- Contains a
string that mailx displays to prompt for
output in command mode. The default is a question mark followed by
a space (? ).
- quiet
- Does not display
the opening message and version number when mailx begins
a session. The default is noquiet.
- record
- Contains a
file name where every message you send is to be recorded. If record is
not an absolute path name and the outfolder variable has not
been set, the file is located in the current directory. If the outfolder variable
is set, the file is located in your folder directory. The default
is norecord.
- replyall
- Reverses the
senses of the reply and Reply subcommands
(so that reply replies only to the author
of a message, and Reply replies to the author
and all other recipients). See also flipr.
- save
- Saves messages
in your dead.letter file if they are interrupted while being
composed. The name of your dead.letter file is given by the dead variable.
Setting nosave disables this automatic save feature. The default
is save.
- screen
- Gives the
number of headers that are to be displayed by the headers and z subcommands. If screen is
not specified, the current window size shall be used to determine
the number of headers displayed.
- sendmail
- Contains a
command, possibly with options, that mailx invokes
to send mail. The default is /usr/lib/tsmail.
It can be any command that takes addresses on the command line and
message contents on standard input.
- sendwait
- When sending
a message through a network, mailx waits
for the mail server to finish before returning to your session. Normally,
it just submits the message to the server and then returns immediately.
The default is nosendwait.
- showto
- When displaying
a header summary, displays the recipient's name instead of the author's
for messages where you are the author. The default is noshowto.
- sign
- Contains a
string that is inserted into a message when you use the input mode ~a subcommand. mailx interprets \n and \t in
this string as the newline and tab characters, respectively. The default
is nosign.
- Sign
- Contains a
string that is inserted into a message when you use the input mode ~A subcommand.
The default is noSign.
- toplines
- Gives the
number of header lines that the top subcommand
is to display. The default is 5.
Files
mailx uses
the following files:
- /etc/mailx.rc
- System-wide startup file.
- $MAILRC
- Personal startup
file. By default, MAILRC has the value $HOME/.mailrc.
- $HOME/mbox
- Default location to save
read messages. You can choose a different file by assigning the file
name to the environment variable MBOX.
- $MAILDIR
- Directory containing system
mailboxes. By default, this is /usr/mail. The system programmer
must create the MAILDIR directory if it does not already exist.
See z/OS UNIX System Services Planning for information
about electronic
mail.
If you use a system
mailbox directory other than /usr/mail, identify it in the
$MAIL environment variable in /etc/profile. See the section
on customizing /etc/profile in z/OS UNIX System Services Planning.
- $HOME/dead.letter
- Default location to save partial letters.
Localization
mailx uses
the following localization environment variables:
- LANG
- LC_ALL
- LC_CTYPE
- LC_MESSAGES
- LC_TIME
- LC_SYNTAX
- NLSPATH
See Localization for more
information.
Exit values
- 0
-
- Successfully sent. (However, this does not guarantee that the
mail was successfully received.)
- 0 is returned if -e is specified and
mail was found.
- 1
- Returned if –e is specified and mail
was not found or an error occurred. Also returned to indicate failure
due to any of the following:
- There is no mail to read.
- Inability to create temporary file name or temporary file.
- Receipt of user interrupt while message was being composed.
- Inability to determine the user's identity.
- 2
- Failure due to any of the following:
- Missing number after –h
- Missing address after –r
- Missing subject after –s
- Missing user after –u
- Incorrect command-line option
- Use of interactive options when not using command interactively
Portability
POSIX.2, X/Open Portability Guide, UNIX System V.
UNIX System V
has a compatible mailx utility, whereas
Berkeley Software Distribution (BSD) has a similar utility, known
as Mail.
The –F, –r,
and –U options; the Copy, echo, followup, Followup, Save, Unread,
and version subcommands; and the allnet, conv, mailserv, onehop, replyall, sendmail,
and sendwait variables are extensions of the POSIX standard.
Related information
echo, ed, sh, vi