help-bash
[Top][All Lists]
Advanced

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

Re: 255 return code from wait builtin


From: Greg Wooledge
Subject: Re: 255 return code from wait builtin
Date: Wed, 22 Jan 2025 08:26:56 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

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?



reply via email to

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