help-bash
[Top][All Lists]
Advanced

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

Re: is there a way to save stdout and stderr to two bash variables?


From: Chet Ramey
Subject: Re: is there a way to save stdout and stderr to two bash variables?
Date: Tue, 12 May 2020 09:52:46 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

On 5/12/20 5:44 AM, Peng Yu wrote:

>     Also, if you do not allow even internal usages of external files at
>     all, you cannot use here documents and here strings as they also use
>     temporary files internally.  For example, you can confirm this by the
>     following command.
> 
>     $ ls -la /dev/fd/0 <<< Here
>     lr-x------. 1 murase murase 64 2020-05-12 09:42:22 /dev/fd/0 ->
>     /tmp/sh-thd.ZLmXgN (deleted)
> 
> 
> I didn’t know that this was the case. I always thought heredoc was in memory.

That's not a good assumption. This list has seen a dozen discussions of the
historical bash implementation of here docs and here strings.

> Chet, There was not an in memory implementation of here doc possible in
> bash? How much performance difference it could be comparing in memory and
> temp file (suppose temp file is not in a RAM disk)?

You have to turn that memory into a file descriptor. There are a few ways
to do that: a temp file, a pipe, and mmap-style file mapping (which
requires a file and file descriptor anyway). The devel branch uses pipes
if the here document or here string is smaller than the pipe size, and
a temp file otherwise.

There was a long discussion about this a year ago, starting with

https://lists.gnu.org/archive/html/bug-bash/2019-04/msg00007.html

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

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