Name

getline

Synopsis

getline [varhairsp;] [< file]

command | getline [var]

Description

The first form reads input from file or the next file on the command line, and the second form reads the output of command. Both forms read one line at a time, and each time the statement is executed it gets the next line of input. The line of input 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 neither $0 nor NF is changed. Thus, if the result is assigned to a variable, the current line does not change. getline is actually a function, and it returns 1 if it reads a record successfully, 0 at EOF, and -1 if for some reason it is otherwise unsuccessful.

Get Linux in a Nutshell, Third 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.