Date:        Mon, 26 Jan 2026 13:46:32 +0200
    From:        Jari Aalto <[email protected]>
    Message-ID:  
<caou7hic8odr9w2mkq4vgdjmmto080xojivbhr31p3cq1deg...@mail.gmail.com>

This is not a bug,

  |         See code below.
  |         - The old backtics `` work
  |         - The modern $() doesn't

Parsing $() requires parsing the command inside the () in order to locate
that closing ')'.   Parsing that detects the #, from which point everything
to end of line is a comment (including the ')' - chars in comments are
never interpreted).

Backtick parsing is much simpler, just look for the next unescaped backtick
(even quoting doesn't hide them, just \) so everything is quite different in
that case.

  | Fix:
  |         The process substitution is defined in POSIX and
  |         should work identically in both cases.

Almost nothing is identical between backtick and $() command
substitutions (not process substitutions, which are definitely
not defined by POSIX, though bash implements a version).

Every shell I could think of to test gives a syntax error for
the $(#comment) version.   That absolutely guarantees that
even if the standard says something different (which I don't
think it does) it would be wrong, and be corrected in the
next version (if someone tells them about it).

kre

Reply via email to