Web lists-archives.com

Re: BASH 4.4 mapfile/readarray/read builtins mis-behaving with pipe




On Sun, 15 Jul 2018 19:01:21, BloomingAzaleas wrote:
CASE:
echo multi-line_arg | read foo
cat multi-line_unix_fmt_file | read foo
 =C2=A0RESULT:
Fail with variable foo null or unset

CASES: left chev re-directions
mapfile < some_unix_fmt_file
mapfile <<END multi-line_here_doc
read < some_unix_fmt_file
read <<END multi-line_here_doc
RESULT:
Work as expected

CASES: mapfile or read in a sub-shell
echo multi-line_arg | ( mapfile ; stuff )
echo multi-line_arg | ( read foo; stuff )
RESULT:
Work as expected.=C2=A0 However, since mapfile/read result vars are=20
not accessible in parent shell context, can force a notable=20
re-structuring of a script to use sub-shells.

no mis-behaving: this is intended behavior - you yourself have given
workarounds: either redirect output to a file that can be later read, or pipe to
command grouping ala {} or () and read stdin from inside the subshell

im not sure what you are asking here - it seems you have a grasp already of the
"problem" and "solution" - so nothing more needs to be said really, as nothing
needs to be fixed - another option is "lastpipe"

http://mywiki.wooledge.org/BashFAQ/024


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple