read command in Unix/Linux

Reads one line from standard input.

The read command reads one line from standard input and assigns the values of each field in the input line to a shell variable using the characters in the IFS (Internal Field Separator) variable as separators.

The Variable Name parameter specifies the name of a shell variable that takes the value of one field from the line of input. The first shell variable specified by the Variable Name parameter is assigned the value of the first field, the second shell variable specified by the Variable Name parameter is assigned the value of the second field, and so on, until the last field is reached.

If the line of standard input has more fields than there are corresponding shell variables specified by the Variable Name parameter, the last shell variable specified is given the value of all the remaining fields. If there are fewer fields than shell variables, the remaining shell variables are set to empty strings.

    Note: If you omit the Variable Name parameter, the variable REPLY is used as the default variable name.

p     Reads input from the output of a process run by the Korn Shell using |& (pipe, ampersand).
 
Note: An end-of-file character with the -p flag causes cleanup for this process so that another can be spawned.
-r     Specifies that the read command treat a \ (backslash) character as part of the input line, not as   a      control character.
-s     Saves the input as a command in the Korn Shell history file.
-u [ n ]     Reads input from the one-digit file descriptor number, n. The file descriptor can be opened with the ksh exec built-in command. The default value of the n is 0, which refers to the keyboard. A value of 2 refers to standard error.

To save a copy of the input line as a command in the history file, type:
read -s line < input_file
If input_file contains “echo hello world,” then “echo hello world” will be saved as a command in the history file.

Advertisements

About victimizeit
This is Atul.. working for IBM as a DataStage Developer. I may not be an expert on any particular DataStgae technology, but I'm sure I do know a few things about DB2, AIX, Unix, Windows, and DataBase. In this blog, I'll give out some tips on these subjects. If you find them useful, great, I'll be happy. Thanks for stopping by !!

What is your opinion ?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: