Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16499 > unrolled thread

Re: Undocumented feature: Unnamed fifo '<(:)'

Started byChet Ramey <chet.ramey@case.edu>
First post2020-06-30 12:30 -0400
Last post2020-06-30 12:30 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Undocumented feature: Unnamed fifo '<(:)' Chet Ramey <chet.ramey@case.edu> - 2020-06-30 12:30 -0400

#16499 — Re: Undocumented feature: Unnamed fifo '<(:)'

FromChet Ramey <chet.ramey@case.edu>
Date2020-06-30 12:30 -0400
SubjectRe: Undocumented feature: Unnamed fifo '<(:)'
Message-ID<mailman.714.1593534671.2574.bug-bash@gnu.org>
On 6/28/20 9:49 AM, felix wrote:

> Bash Versions: 3.2.57(1)-release, 5.0.3(1)-release, 5.1.0(1)-alpha
> 
> In order to reduce forks and make some tasks a lot quicker, I run
> forked filters as background tasks, with dedicated I/O fd.
> 
> For sample, to convert human datetime to UNIX SECONDS, instead of running
>    _out=$(date -d "$_string" +%s)
> many time in same script, I run something like:
> 
>     _fifo=$(mktemp -u /tmp/fifo-XXXXXXXX)
>     mkfifo $_fifo
>     exec 9> >(exec stdbuf -o0 date -f - +%s >$_fifo 2>&1)
>     exec 8<$_fifo
>     rm $_fifo
> 
> Then to convert human datetime to UNIX SECONDS:
> 
>         echo >&9 $_string
>         read -t 1 -u 8 _out
> 
> become a lot quicker!
> 
> But I recently discovered another way for this:
> 
>     exec 8<> <(:)
>     exec 9> >(exec stdbuf -o0 date -f - +%s >&8 2>&8)
> 
> usable in same way:
> 
>         echo >&9 $_string
>         read -t 1 -u 8 _out
> 
> maybe a little more quicker...

But not guaranteed to work everywhere, especially those systems that use
/dev/fd and pipes for this instead of FIFOs. (And lack `stdbuf'.)

> There is maybe something to document or even create a new feature
> about open2 and open3...

No, it's not. But if it works for you, go ahead and use it. Just be
prepared to have to change it if necessary.

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

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web