bug-bash
[Top][All Lists]
Advanced

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

Re: redirecting a file descriptor to an array variable? Possible? How? R


From: Linda Walsh
Subject: Re: redirecting a file descriptor to an array variable? Possible? How? RFE?
Date: Sun, 15 Nov 2015 05:26:26 -0800
User-agent: Thunderbird



Greg Wooledge wrote:
On Thu, Nov 12, 2015 at 04:45:49PM -0800, Linda Walsh wrote:
I'm coming up with a null-record in my brain when I think
about this:  I'd like to be able to record stdout and stderr
without using any temp files into bash array files, AND
record the status of the command executed.

There is no way to do this currently.  Storing stdout and stderr
separately requires at least one temp file.  (Actually in the most
general case, where those output streams may contain NUL bytes,
it requires two temp files, because you can't store arbitrary data
streams in bash variables at all.)
----
        In the simple case, presume there are no NUL bytes.

        In the more complex case, presume
readarray has a "-0" switch which uses null bytes (trimmed)
as line separators.
        Note that printf *can* print out nul bytes:
printf "\"%c\"\n" $'\x00' |hexdump -C
00000000  22 00 22 0a                                       |".".|
00000004

        But contrary to the manpage under printf:
" The -v option causes the  output  to  be
 assigned  to  the  variable var rather than being printed to the
 standard output. "

printf does not print the output of the above into a var instead
of stdout.
Seems like that would be a bug?

If I am in a locale using UTF-16, there will be lots of 'NUL'
chars if I view that output as binary -- so there has to be one
or more ways to encode NUL bytes in a var such that they don't
terminate the string.
Nevertheless, printf doesn't follow the documented behavior on the
manpage and print stdout to the variable.

If the issue of varables being able to contain any sequence of
binary bytescould be solved, it might make it easier to solve
the problem of streaming std[out/err] to a variable or an array.

No?





reply via email to

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