[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to set $?
From: |
Jeffrey Walton |
Subject: |
Re: How to set $? |
Date: |
Sun, 26 Dec 2021 14:56:00 -0500 |
On Sat, Dec 25, 2021 at 6:22 PM Greg Wooledge <greg@wooledge.org> wrote:
>
> On Sun, Dec 26, 2021 at 09:40:34AM +1100, David wrote:
> > Should be:
> > apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
> > saved_result=$?
> > apt-get autoremove --purge -y && apt-get autoclean -y
> > exit "$saved_result"
>
> Ah, I should have read the original question more closely.
>
> The LITERAL question that was asked was "how to set $?" which I answered
> in a very straightforward way.
>
> But the ACTUAL question should have been "how do I set the exit status of
> my script when exiting", which you have answered here.
Actually, I wanted to set $? in two places.
The other way - tracking $ret_val and then `exit $ret_val` - required
changes in 72 places.
Jeff