[Top][All Lists]

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

Re: Command substitution and errexit

From: Greg Wooledge
Subject: Re: Command substitution and errexit
Date: Mon, 15 Oct 2012 16:13:39 -0400
User-agent: Mutt/

On Mon, Oct 15, 2012 at 04:00:01PM -0400, DJ Mills wrote:
> I'm also not entirely sure what you mean by "errexit will always be
> stored as off."

My interpretation is that he wants to write a "portable function" for
someone else to use, and that he wants to use errexit while inside it,
and therefore he believes he needs to retrieve the current value of
errexit so that the can restore that value right before exiting.

So, he's trying to capture stuff=$(set +o) to retrieve the settings,
but since errexit gets disabled in (some? I don't know/care) subshells,
it's not acting as he expects.

imadev:~$ bash -c 'set -e; set +o | grep errexit'
set -o errexit
imadev:~$ bash -c 'set -e; x=$(set +o); echo "$x" | grep errexit'
set +o errexit

I reiterate my position that set -e (errexit) should be avoided.  It
brings nothing but suffering.

reply via email to

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