Counter in sh inside loop, value "encapsulation"

Christian Weisgerber naddy at mips.inka.de
Thu Dec 5 21:05:16 UTC 2019


On 2019-12-05, RW via freebsd-questions <freebsd-questions at freebsd.org> wrote:

> IIRC when this sort of thing came once before someone posted a way of
> processing the output of a pipeline and having multiple variables
> directly accessible to the main script. 
>
> It didn't involve creating files or sockets, or storing the output of
> the pipeline in a single variable. There was some trick that avoided
> last stage being done in sub-shell.

Instead of

  cmd | while read var; do ...; done

you can use

  while read var; do ...; done <<EOF
  $(cmd)
  EOF

-- 
Christian "naddy" Weisgerber                          naddy at mips.inka.de


More information about the freebsd-questions mailing list