[Top][All Lists]

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

Re: bash uses tmp files for inter-process communication instead of pipes

From: Chet Ramey
Subject: Re: bash uses tmp files for inter-process communication instead of pipes?
Date: Tue, 07 Oct 2014 11:48:06 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 10/7/14, 2:07 AM, Linda Walsh wrote:

> I thought I was getting rid of this bogus problem (which shouldn't
> be a problem anyway -- since it's just another pipe but with parent receiving
> the data instead of child receiving it) by storing it in a variable
> transfer form
> <<<($VAR)... cuz was told that didn't involve a voodoo process-substitution.

I suppose it's voodoo because you didn't understand the underlying OS
resource process substitution uses and therefore didn't realize when that
resource is and is not available.  People using process substitution using
/dev/fd on a system like FreeBSD also encounter similar issues, since
/dev/fd is a separate file system that must be mounted.

> But it involves a heredoc that even though /tmp and /tmp/var are writeable,
> BASH can't use.  Either it's writing to //network or trying to open a
> tmp file in the current (/sys) directory... eitherway is buggy.

You misunderstand what is going on, but now that you know here documents
and here strings use temporary files, and that, as documented, bash uses
$TMPDIR as the directory where it creates these temporary files, you can
modify your script to set TMPDIR appropriately.

> But a heredoc is just reading from an in-memory buffer.  That bash is
> going the inefficient route and putting the buffer in "tmp", first, is
> the 2nd problem you are pointing out -- why do people who want a heredoc
> need a fork OR a tmpfile?   The output I generated is < 512 bytes.  Would it
> be too silly to simply put any heredoc output <X[KMG]** in memory and not
> write it to any file?  shopt heredocsize=XXX[KMG]... and overflow to tmp
> if needed.

Maybe.  At some point, however, you have to turn it into a file descriptor,
because that is what the redirections produce.  That constrains your set of
choices.  You could invent new syntax, but it would not be a here-document
or here-string any more.

> Having several that would work woudl be nice.  Um... having 1 that would
> work even... how do you turn around parent/child I/O and get the vars on the
> other side without heredoc or procsub?  Why no pipes?

There are several mechanisms.  You simply have to use them correctly.
Since you're running a non-interactive shell without job control enabled,
you could even use pipes and the `lastpipe' shell option, but that only
first appeared in bash-4.2.

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

reply via email to

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