Hitachi

JP1 Version 11 JP1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide 


9.3.20 read command (reads from the standard input and stores the input in variables)

Syntax

read  [-p] [-r] [-u [num]] [varname ...]

Description

This command reads one line at a time from the standard input and stores the input in specified shell variables.

Arguments

-p

Specifies that the command is to read from the output of a background process through a pipe.

-r

A \ (backslash) is not treated as an escape character.

If a \ (backslash) is included in the contents to be read, the read command treats the backlash as an escape letter. If a \ (backslash) is included in the line, the read command treats the backlash as an escape letter even if the character followed by the backlash is the delimiter defined by using the shell variable IFS. If a backlash is specified at the end of the line, the next line is continuously read. Use the -r option if the \ (backslash) is not to be treated as an escape character.

-u [num]

Specifies the file identifier of the file from which the input is to be read. If no value is specified, the standard input is read.

Specify either a file identifier or p. Specifying p is equivalent to specifying the -p option.

varname

Specifies the name of a variable in which input that is read is to be stored.

When multiple variable names are specified, the input line is split into the fields delimited by the delimiter set in the IFS variable, and the fields are assigned to the variable names in sequential order (input line's first field is set in the first variable, second field is set in the second variable, and so on).

If the number of fields exceeds the number of variable names, the values of all the remaining fields are stored in the last variable that is specified.

If there are fewer fields than there are variables, a linefeed is set in each additional variable.

Return codes

Return code

Meaning

0

Normal termination

1

Normal termination

  • The end of file (EOF) was detected.

Error termination

  • Other than the above.

Notes

Examples