write — Write to another user

Format

write user_name [terminal]

Description

write lets you send a message directly to the terminal of someone else logged in to the system. It reads from the standard input (stdin) and writes to the terminal of another user.

Options

user_name
Specifies the user to whom you want to send your message.
terminal
Is an optional identifier for use when the other user is logged in on more than one terminal. The format of the terminal name is the same as returned by who.

Usage notes

  1. When you issue a write command to send a message to another user, the other user receives a message of the form:
    Message from your_name (terminal) [date] …

    After the system establishes the connection to the other user, it sends two alert characters (typically beeps) to your terminal to tell you that it is ready to send your message. You can then type your message, which will appear on the other user's terminal. To end your message, enter end-of-file or an interrupt (typically, <EscChar-D> for end-of-file or <EscChar-C> for an interrupt, where EscChar is normally the cent sign; if you use rlogin or telnet to enter the shell, you hold down the Ctrl key while you press either D or C). When write receives an indication for end-of-message, it tells the other user that the message is over and breaks the connection.

    The other user can reply to your message with:
    write your_user_name

    However, if both of you are trying to write on each other's terminal at the same time, the messages may get interleaved on your screens, making them difficult to read. For two-way conversations, use talk instead of write.

  2. You can add the output of a command to the material that you write. To do this, start a line with an exclamation mark (!) and put a standard system command on the rest of that line. write calls your shell to execute the command, and sends the standard output (stdout) from the command to the other user. The other user does not see the command itself or any input to the command. For example, you might write:
    Here is what my file contains:
    !cat file
  3. The mesg command lets you refuse write messages. With:
    mesg n
    you can tell the system that you don't want to be interrupted by write messages. If people try to write to you, they are denied immediately; the system does not inform you about such attempts. For further details, see mesg.

Localization

write uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • LC_SYNTAX
  • NLSPATH

See Localization for more information.

Exit values

0
write successfully wrote a message, or the intended recipient used mesg to refuse messages (either before you start sending a message or as you are sending the message).
1
Failure due to any of the following:
  • user_name is not signed on
  • You do not have permission to write on that user's terminal
  • write cannot open the target terminal for writing
  • The command line had an incorrect number of options

Portability

POSIX.2 User Portability Extension, X/Open Portability Guide, UNIX systems.

Related information

mailx, mesg, talk, who