On Wed, Jan 22, 2025 at 12:39:44 +0000, Ian via wrote:
> When I wrap the wait builtin with a command substitution it returns a 255
> code. Why is this?
Don't do that. A command substitution forks a subshell. You're trying
to wait for your main shell's child in a subshell process which is not
the parent of the process you're trying to wait for.
> # This is surprising
> sleep 1 &
> a=$(wait $!) # <---- only difference is cmd substitution
> echo $? # prints "255"
The subshell can't wait for that process because the subshell is not
the process's parent.
Also, the wait command doesn't write anything to stdout, so what are
you even trying to capture in the "a" variable?