Previous | Table of Contents | Next |
DESCRIPTION
The external write command sends messages you type on your terminal to another user's terminal. write reads the standard input and writes to the specified user's terminal tty.
COMMAND FORMAT
Following is the general format of the write command.
write user_name [ tty ]
Arguments
The following list describes the arguments that may be passed to the write command.
user_name | The name of a user who is currently logged in to the system. Use the who command to list who is on the system. |
tty | Specify which terminal tty to connect to if the same user name is logged on more than once. |
FURTHER DISCUSSION
write begins the conversation by sending the destination user two bells (terminal beeps) and a message stating that you are sending a message to his/her terminal. Once write makes the connection, your terminal will beep twice to acknowledge the sending of your message.
If the recipient responds by using write, you will receive two bells and a message. As the other user enters lines of text they will appear on your terminal screen. At this point you can both send and receive lines of text from each other.
Problems may arise if you both don't adhere to a telephone protocol; one listens while the other one speaks, a.k.a. common phone courtesy. If you both send messages at the same time, your screens will become garbled with your text and the other user's messages that are arriving on your screen.
It is advisable to establish the following protocol if you plan on having a bidirectional conversation.
The protocol does not have to be followed, although it is suggested for conversations. If you only want to send a brief one- or two-line message, then you can perform the write command and enter the text before the other user has to respond. You can also place the message you want to send in a file and redirect the input from the file to write. Here is an example of using redirection:
cj> write tlp < tmpmesg
This will write the entire contents of the tmpmesg file to user tlp.
The following display shows a conversation between two users on the system. Assume your terminal is the left column and the user named bill is viewing the right-hand column from his terminal. The bold print is what you type; normal type is what you receive when Bill types a message. Periods at the far left and right of the display mark filler lines added to the display to make it more understandable.
From your terminal tty11 -to- Bill's terminal tty05 cj> write bill bill> . . Message from mylogin tty11 ... . write mylogin Message from bill tty05 ... . . Hi Bill, Hi Bill, Lunch at 11:00 (o) Lunch at 11:00 (o) . . Sounds good to me! Sounds good to me! (o) . . Ok, see you then. (oo) Ok see you then. (oo) . . Ctrl-D EOT cj> Ctrl-D bill>
If a user is logged in more than once, you must specify to which tty you wish to send your message. If you do not specify the tty, write will assume you want to send to the first user listed in the /etc/utmp file. write notifies you of the situation by displaying the following information:
Assume nancy is a port hog and is logged in on tty07 and tty14.
cj> write nancy nancy is logged on more than one place. You are connected to /dev/tty07 Other locations are: /dev/tty014
You may grant or deny other users write permission to your terminal by using the mesg command discussed in Module 88. You can toggle between the two permissions. Mesg -n denies access and mesg -y grants access. The super-user can force messages to a terminal that has been set to deny messages.
Some commands perform a mesg -n when they start, to prevent other users from writing to your terminal while they execute. The pr and vi commands are the most common of these commands.
You can escape from write to perform other commands. If you type a ! (exclamation mark) at the beginning of the line, write will interpret the rest of the line as a command. The shell is executed first and the command is passed to the new shell for interpretation and execution.
DIAGNOSTICS AND BUGS
The following list of messages are produced by write depending on the given situation.
"user is not logged in" | |
The user you want to write to is not logged on to the system. Execute the who command to find out who is logged on. | |
"Permission denied" | |
The person you are trying to write has denied other users from writing to his/her terminal. This means the recipient has done a mesg -n. | |
"Warning: cannot respond, set mesg -y" | |
You have your message permission set to no. The recipient cannot respond (write) to your terminal. Change your permission by typing !mesg -y. | |
"Can no longer write to user" | |
The recipient performed a mesg -n after you started your write command. This denies you permission to write to the recipient's terminal. |
RELATED COMMANDS
Refer to the mail, mesg, ksh, talk and who commands described in modules 86, 88, 82, 132, and 159 respectively.
RELATED FILES
The following files are used by write:
/etc/utmp | Used to locate the destination user. The tty is also retrieved from this file. |
/etc/ttyXX | A tty device file is used to write to the other user. |
standard input | The input is read from your terminal unless redirected from a file or piped from a previous command. |
APPLICATIONS
The write command is used to communicate with fellow users on an interactive basis. It is useful to send a brief message to someone immediately or to carry on conversations using terminals. The talk command is a much more sophisticated utility for having interactive conversations, while write serves you better when only needing to send a quick message to a user's terminal. If you want to send someone a note, letter, or a file and they are not logged on, you should use the mail command.
TYPICAL OPERATION
In this activity you use the write command to send a string of text to the user name tlp. Begin at the shell prompt.
tlp> Message from mylogin tty11 ... How about meeting in the small conference room @ 9:00
Previous | Table of Contents | Next |