bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Data piped to 'mapfile', 'readarray', 'read -a' shell builtins is ig


From: Pierre Gaston
Subject: Re: Data piped to 'mapfile', 'readarray', 'read -a' shell builtins is ignored
Date: Wed, 24 Mar 2010 16:10:41 +0200

On Wed, Mar 24, 2010 at 12:43 AM, Rob Robason <rob@robason.net> wrote:

> Configuration:
>    OS: Fedora 11 - with all updates applied
>    Bash: version 4.0.23(1)-release
>
> Problem description:
> When stdin is a pipeline to 'mapfile', 'readarray', and 'read -a' shell
> built-in commands, they fail to assign any values to the target array.
> The array is neither unset nor altered in any way. No error message is
> produced, and $? == 0.
> None of the available options have any effect on this behavior.
> Oddly, when input is provided via keyboard or redirection (<), these
> commands function properly. This last point seems really weird to me and
> points to the built-ins' or shell's internal handling of a pipeline.
>
> mapfile/readarray example (mapfile behaves identically to readarray):
>    $ ls -a | readarray            # using the default MAPFILE array
>    $ echo $?
>    0
>    $ echo "${#MAPFILE[@]}"
>    0
>    $
>
> Other forms of mapfile/readarray that fail:
>    $ ls -a | readarray -u0        # specified input file descriptor
>    $ echo "${#MAPFILE[@]}"
>    0
>    $
>
>    $ declare -a myArray           # (optional) Declaring myArray has no
> effect
>    $ ls -a | readarray myArray
>    $ echo "${#myArray[@]}"
>    0
>    $
> a


It's a faq, commands in a pipe are executed in a subshell and don't modify
the parent shell.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]