Replies: 4 comments
-
I have tried to use it briefly in the past, and like you found it mostly useless. I can't remember exactly what problems I had, but I suspect the return values of assignments was the deal breaker (where assignments of course include things like function definitions). The way I think about '-e' is that it's trying to catch results you've ignored, and if you've assigned the result you haven't ignored it, just like if you used it in the condition of an if statement. The current behaviour is the one that's surprising. Having said that, I don't really understand how the original authors used it; perhaps it's a regression. It might be worth going back to when it was originally introduced and seeing if es behaved differently. |
Beta Was this translation helpful? Give feedback.
-
Well, I have a couple guesses here.
|
Beta Was this translation helpful? Give feedback.
-
I believe this is due to the Unix-oriented shell semantics associated with truthiness. To simplify things, a list is considered "true" if it is empty, i.e.
Everything else is considered "false", including
This is likely why you think you experienced issues with your |
Beta Was this translation helpful? Give feedback.
-
Okay, I've convinced myself that the fact that By my reasoning, the reason we have the The relevant code is if (flags & eval_exitonfalse)
dispatch = mklist(mkstr("%exit-on-false"), dispatch);
varpush(&push, "fn-%dispatch", dispatch);
repl = varlookup((flags & run_interactive)
? "fn-%interactive-loop"
: "fn-%batch-loop",
NULL);
result = (repl == NULL)
? prim("batchloop", NULL, NULL, flags)
: eval(repl, NULL, flags); The problem, as I see it, is that The right behavior here is to clear the if (flags & eval_exitonfalse) {
dispatch = mklist(mkstr("%exit-on-false"), dispatch);
flags &= ~eval_exitonfalse;
} This makes |
Beta Was this translation helpful? Give feedback.
-
I was poking around with changing es' exit-on-false behavior to throw an exception on false, similar to how the
exit
command works by throwing an exception, and I realized thates -e
is actually pretty difficult to use -- especially given the "assigments return the value" behavior es has.So, I'm curious -- does anybody use
es -e
for their scripts?Would it be easier or harder to use if assignments were special-cased not to cause
$&exitonfalse
to "fire"? Would that be worth the extra complexity and (potentially) extra surprise?Incidentally, it actually causes an interactive shell to immediately exit for me, because my
%prompt
ends with an assignment. (Also my%write-history
when using #65). Do people agree that that's weird --%prompt
shouldn't make the shell exit, even with the-e
flag enabled?Curious about others' thoughts -- since I don't tend to use this feature much, I don't trust my intuition a ton on it. (I do strongly feel that it should use an exception, though.)
Beta Was this translation helpful? Give feedback.
All reactions