Re: Dash 0.5.12 bug - POSIX process substitution $() handling error with embedded comments

Harald van Dijk <[email protected]> Mon, 26 Jan 2026 12:18:42 +0000
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On 26/01/2026 11:55, Jari Aalto wrote:
> The process substitution is defined in POSIX and
> should work identically in both cases.

It is defined by POSIX in such a way that it is not required to work 
identically in both cases.

> COMMAND:
> 
> bash -x <code>

As your testing will have shown, bash and dash behave the same here.

> # OK
> x=`# comment`

This works because ` is looked up without regard to shell syntax. But 
POSIX says this is undefined:

> The search for the matching backquote shall be satisfied by the first
> unquoted non-escaped backquote; during this search, if a non-escaped
> backquote is encountered within a shell comment, a here-document, an
> embedded command substitution of the $(commands) form, or a quoted
> string, undefined results occur.

This is precisely the case that is made undefined: your closing ` is 
encountered within a shell comment.

> #  Syntax error: end of file unexpected (expecting ")")
> x=$(# comment)
This doesn't work because ) is looked up with regard to shell syntax. A 
) in a comment is treated like any other character in a comment, it does 
nothing.

To use a comment in a command substitution, ensure the terminating 
newline is part of the command substitution.

x=`# comment
`

x=$(#comment
)

Cheers,
Harald van Dijk