Name
getline
Synopsis
getline getline [var
] [<file
]command
| getline [var
]command
|& getline [var
]{G}
Read next line of input.
The second form reads input from file
and the third form reads the output of
command. All forms read one record at a time,
and each time the statement is executed it gets the next record of
input. The record is assigned to $0
and is parsed into fields, setting
NF
, NR
, and FNR
. If var is
specified, the result is assigned to var and
$0
and NF
are not changed. Thus, if the result
is assigned to a variable, the current record does not change.
getline
is actually a function
and it returns 1 if it reads a record successfully, 0 if
end-of-file is encountered, and -1 if for some reason it is
otherwise unsuccessful.
The fourth form reads the output from coprocess command. See the earlier section "Coprocesses and Sockets" for more information.
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.