Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: Linda Walsh Newsgroups: gnu.bash.bug Subject: Re: redirecting a file descriptor to an array variable? Possible? How? RFE? Date: Sun, 15 Nov 2015 05:26:26 -0800 Lines: 52 Approved: bug-bash@gnu.org Message-ID: References: <564532BD.60801@tlinx.org> <20151113131735.GE27325@eeg.ccf.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1447656453 4877 208.118.235.17 (16 Nov 2015 06:47:33 GMT) X-Complaints-To: action@cs.stanford.edu Cc: Greg Wooledge To: bug-bash Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: <20151113131735.GE27325@eeg.ccf.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11884 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?