The read Command


« Previous
Next »

The read Command

Command-line arguments allow a user to pass information into a program when the program is invoked, and the user must know the correct syntax before the command is executed. There are situations, though, in which you would rather have the user execute just the program and then prompt him or her to provide input during the program execution. The read command is used to gather information typed at the terminal during the program execution.

The read command takes one line of input from the user and assigns it to a variable. The variable name is provided as an argument to the read command.

The read command will specify a list of variable names, whose values will be assigned to the words (delimited by white space) that the user supplies at the prompt. If there are more variables specified by the read command than there are words of input, the leftover variables are assigned to NULL. If the user provides more words than there are variables, all leftover data is assigned to the last variable in the list.

Syntax :
read   variable   [ variable ... ]

#!/usr/bin/sh

echo   " Currently logged in users are : "
who
echo  
echo   " Enter the name of the user to whom you want to talk "
read NAME
echo   " initiating talk with $NAME "
talk $NAME
$



After you select a user, the program rings the other party and displays a message asking the other user to respond to your talk request. If that user accepts your request, a talk window appears.


Currently logged in users are:
zen pts/t0 Oct 18 17:53
general pts/0 Oct 18 22:13
Enter the name of the user to whom you want to talk linda < The talk window appears which covers the full screen >




« Previous
Next »