bug-bash
[Top][All Lists]
Advanced

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

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


From: Robert Elz
Subject: Re: Undocumented feature: Unnamed fifo '<(:)'
Date: Mon, 29 Jun 2020 17:06:25 +0700

    Date:        Sun, 28 Jun 2020 17:27:47 -0400
    From:        Eli Schwartz <eschwartz@archlinux.org>
    Message-ID:  <346bda2f-83dc-afda-d911-9688daefb10e@archlinux.org>

  | Sure, and that can be pointed out, but that's a long way away from what
  | Dennis actually said, which is "why not just use a function",

I think we picked up on different words from his message,
what I focused on was:

dennistwilliamson@gmail.com said:
  | How is running your
  |         echo >&9 $_string
  |         read -t 1 -u 8 _out
  | many times better than running your
  |    _out=$(date -d "$_string" +%s)
  | many times? 

which is a good question.

  | implying that the use or not of a function is relevant here.

perhaps, though I didn't read it that way, more as a suggestion
for a better style - though I'd make such a function do the
conversion into a variable, rather than to stdout, which would
allow different implementations - allowing changing just one function
to try out different implementation techniques.

  | IIRC bash will (if it can) optimize out $(cmd) to fork+exec cmd,

I expected it probably would - though I have learned to my cost that
being over agressive in this kind of optimisation can cause bizarre
bugs.   But wven if the optimisation doesn't happen by default, we
can easily force it by using
        $(exec date ,,,)
at which point the shell has no choice.

  | Perhaps the OP is assuming that the
  | fifo dance will result in one fork, rather than two?

Perhaps, but that would be a bizarre way to accomplish that.   I got
the impression that the assumption was that there would somehow be just
one fork, no matter how many times the conversion was required.   I
think that might be possible using bash - but not using date(1) to do
the conversions, it would need a purpose written command which read date
specs from stdin and wrote time_t's (in decimal) to stdout.

  | In fact, I'd assume the $(function) is
  | actively a bad idea as it would prevent bash from optimizing out the
  | $(/usr/bin/date) fork.)

In the absence of anything else, it shouldn't (or doesn't need to).
When the shell executes the command substitution, it knows the function
is the last command it will run (assuming no traps, ...) and then in
the function, it will know that date is the last command in the function,
the last of the last, exec is OK.

kre




reply via email to

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