[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mapfile documentation
From: |
Greg Wooledge |
Subject: |
Re: mapfile documentation |
Date: |
Fri, 16 Mar 2018 09:22:37 -0400 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Fri, Mar 16, 2018 at 09:14:13AM -0400, Boruch Baum wrote:
> In GNU bash, version 4.4.18(1)-release (x86_64-pc-linux-gnu), the first
> line of the documentation for readarray / mapfile states:
>
> Read lines from the standard input ...
>
> However, it doesn't seem to accept input from a pipe. It would be
> helpful to note that.
It does. What you're running into is the fact that each component of
the pipeline is run in a separate subshell, so any variables assignments
made during the pipeline (including read or mapfile) are lost once the
pipeline is completed.
https://mywiki.wooledge.org/BashFAQ/024
Demonstration:
wooledg:~$ printf %s\\n one two | (mapfile -t array; declare -p array)
declare -a array=([0]="one" [1]="two")
wooledg:~$ declare -p array
bash: declare: array: not found
The "array" variable was created in a subshell, so it's gone once
the pipeline has finished.
Re: mapfile documentation, L A Walsh, 2018/03/16