News for hackers. Stuff that matters.
Re:Understanding Bash (2018) by empath75 on Thursday January 16, 2020 @10:13AM (#22065213)
> Note that the exit value of true is 0, and the exit value of false is 1. This is somewhat counterintuitive, and it's the exact opposite of most programming languages.

"Happy families are all alike; every unhappy family is unhappy in its own way."

https://en.wikipedia.org/wiki/Anna_Karenina_principle

Re:Understanding Bash (2018) by reportgunner on Thursday January 16, 2020 @11:21AM (#22065971)
This is there to allow more than just true and false, like warnings and custom exit codes.

https://stackoverflow.com/questions/4419952/difference-betwe...

I have also encountered this in C#

https://docs.microsoft.com/en-us/dotnet/api/system.environme...

Re:Understanding Bash (2018) by AdmiralAsshat on Thursday January 16, 2020 @10:32AM (#22065428)
It took me awhile to wrap my head around when I initially encountered it, but the idea made sense after I thought about it. If the process exited successfully, we don't care--it did what it was supposed to do. But if it failed, we'd probably like as much info about why it failed as possible; and so having the exit status be more like an error code clearly has some value.
Re:Understanding Bash (2018) by elmigranto on Thursday January 16, 2020 @11:05AM (#22065788)
Good point. I think the fact that it’s named “exit status” instead of “error code” is primary confusion factor.
Re:Understanding Bash (2018) by empath75 on Thursday January 16, 2020 @01:46PM (#22067557)
I was being somewhat oblique about it but that was what my quote was saying.
Re:Understanding Bash (2018) by michaelcampbell on Thursday January 16, 2020 @11:18AM (#22065933)
Some older versions of BASIC did this as well, except false was -1.

I think internally it was represented as all 0 bits for true, all 1 bits for false.

To be pendantic, at least in terms of bash if's, ['s, and test's, I think 0 is true and non-0 is non-true though, no?

Re:Understanding Bash (2018) by flingo on Thursday January 16, 2020 @01:50PM (#22067600)
I certainly prefer this to the reverse, and having truth values and return values mean something different.
Re:Understanding Bash (2018) by banachtarski on Thursday January 16, 2020 @11:53AM (#22066299)
The article is wrong though. For error codes, 0 being a success value is the CONVENTION. A non-zero code is an error. This isn't about "programming languages."
Re:Understanding Bash (2018) by SAI_Peregrinus on Thursday January 16, 2020 @02:07PM (#22067758)
The problem is that for bash `true` is a function (or builtin) that returns 0, while for C (and thus most languages) any non-zero value (typically 1 for the builtins) is true. In c99 and later with stdbool.h, `true` is almost always defined as `#define true 1`.
Re:Understanding Bash (2018) by aidenn0 on Thursday January 16, 2020 @02:50PM (#22068172)
the existence of the && and || operators (not to mention the true and false utilities) would indicate it's more than just a convention.
Re:Understanding Bash (2018) by gbacon on Thursday January 16, 2020 @12:27PM (#22066695)
Wrong is a bit harsh for a convention or semantics, more like imprecisely worded.