GNU Info

Info Node: (gawk.info)Getline/Variable/Pipe

(gawk.info)Getline/Variable/Pipe


Next: Getline/Coprocess Prev: Getline/Pipe Up: Getline
Enter node , (file) or (file)node

Using `getline' into a Variable from a Pipe
-------------------------------------------

   When you use `COMMAND | getline VAR', the output of COMMAND is sent
through a pipe to `getline' and into the variable VAR.  For example, the
following program reads the current date and time into the variable
`current_time', using the `date' utility, and then prints it:

     BEGIN {
          "date" | getline current_time
          close("date")
          print "Report printed on " current_time
     }

   In this version of `getline', none of the built-in variables are
changed and the record is not split into fields.

   According to POSIX, `EXPRESSION | getline VAR' is ambiguous if
EXPRESSION contains unparenthesized operators other than `$'; for
example, `"echo " "date" | getline VAR' is ambiguous because the
concatenation operator is not parenthesized. You should write it as
`("echo " "date") | getline VAR' if you want your program to be
portable to other `awk' implementations.  (It happens that `gawk' gets
it right, but you should not rely on this. Parentheses make it easier
to read, anyway.)


automatically generated by info2www version 1.2.2.9