bug-bash
[Top][All Lists]
Advanced

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

Re: Special parameter ?


From: Eduardo A . Bustamante López
Subject: Re: Special parameter ?
Date: Fri, 21 Sep 2018 08:17:33 -0700
User-agent: Mutt/1.10.1 (2018-07-13)

On Fri, Sep 21, 2018 at 04:17:11PM +0200, Enrique Soriano wrote:
> > You're seeing the status from the creation of the background job (which is
> > always 0), not from its completion.
> 
> Ah, I see.
> 
> Anyway, the behavior is not coherent with the manual page: in this
> case, $? has the status from the creation of the background job,
> that's not "the status of the most recently executed foreground
> pipeline".

The thing that creates the background job IS a foreground pipeline. It's a 
foreground pipeline that creates a background
job, if that makes sense.

address@hidden:~$ cat t.sh
(exit 2)
(exit 3) & pid=$!
echo $?
wait "$pid"
echo $?

address@hidden:~$ bash t.sh
0
3

I recommend to store the value of $? in a variable if you plan on using it 
afterwards, since it's extremely easy to end
up overriding its value.



reply via email to

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