help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Looking for something like "errexit" for interactive ses


From: Eli Schwartz
Subject: Re: [Help-bash] Looking for something like "errexit" for interactive sessions
Date: Wed, 28 Aug 2019 13:53:10 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

> I'm familiar with how errexit works and its quirks, so it generally
> works the way I expect it to. I still find it useful.

Who cares whether you know how it works or its quirks in the process?

The point here is that it is by definition not useful *here*.

> On Wed, Aug 28, 2019 at 08:50:08AM -0400, Greg Wooledge wrote:
>> Every command drops the user back to the prompt when it finishes, whether
>> the exit status was 0 or non-zero.
> No, it doesn't when errexit is set unless I'm missing something:

Isn't that, uh, kind of the point?

errexit is, appropriately, a command to "exit instead of continuing, if
a non-zero exit status is encountered". Shall we read the manual text?

"Exit immediately if a pipeline (which may consist of a single simple
command), a list, or a compound command (see SHELL GRAMMAR above), exits
with a non-zero status."

If you use errexit it is because you want to, well, exit. What would be
the point of an errexit that only "err"ed and did not "exit"?

Oh, I know, it would be the aforementioned PS1 prompts that give you
cutesy statuses when the previous command failed.

...

Let's turn the question around, by stripping away the confusion and
false representation of your xyproblem.

You have an interactive shell, and it is a perfectly ordinary, normal
interactive shell. You type things in and things happen as a result.
Whatever the outcome of the previous command was, you still get returned
to the prompt, because that is what a prompt *does*, and you weren't
silly enough to type `set -e` into an interactive prompt.

Now you want to do... what? What is your desired goal if a command fails?

By default it will return you to the prompt. You can manually set up
errexit, in which case, it will instead close your shell. But you
specifically said you do not want to close your shell, for which I
applaud your innovative logic.

If you don't want it to close the shell, and you don't want the default
behavior "set the value of $? and return the prompt", then WHAT. DO.
YOU. WANT.

What is your middle ground that you wish to see?

> The "2" indicates the SHLVL, and as shown, you don't get dropped at a
> prompt when errexit is set during an interactive session. I want a
> feature that works like errexit but returns the user to a functioning
> prompt per my original message:

errexit does one thing, and *only* one thing. It says "do not return the
invoking shell to a functioning prompt" (even if that prompt is that a
shell script is prompting the interpreter to read another line of text
from your *.sh file). Once you remove that, it doesn't do anything. So
your original message was a request to "do X, except without doing X".

You have been repeatedly told, "okay, so don't do X". If you want a
better answer, ask a better question.

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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