LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Why do scripting languages use a reverse convention for indicating TRUE and FALSE? (https://www.linuxquestions.org/questions/programming-9/why-do-scripting-languages-use-a-reverse-convention-for-indicating-true-and-false-4175661191/)

orbea 09-20-2019 09:36 AM

Quote:

Originally Posted by hazel (Post 6038609)
OK. "&&" and "||" are boolean operators, aren't they? So how does that work if the exit codes from test and rm are just integers?

Slightly off-topic, but I have seen cases where some shells (Including bash) will just silently exit when using "&&" in some circumstances. It seems to be more common when using "set -e" and at the end of nested loops/conditionals (Adding a "echo" or another command at the end sometimes helps) and when used many times consecutively. On the other hand "||" doesn't seem to suffer from these problems nor does using more canonical test statements.

This can workaround it where the ":" is a no-op.

Code:

{ [ "${foo}" ] && bar; } || :
Or this.

Code:

[ -z "${foo}" ] || bar
I have also not yet seen some shells like dash or mksh suffer from these problems.

NevemTeve 09-20-2019 09:46 AM

Off: When I do this:
Code:

set -e
make all 2>&1 | tee log.make.all

it won't stop if 'make all' fails. Unless I use 'set -o pipefail' too. Which is bash-specific.

ntubski 09-20-2019 07:43 PM

Quote:

Originally Posted by hazel (Post 6038602)
I remember reading in some programming guide or other that it's bad practice to have multiple error codes for different kinds of errors because nobody wants to have to look them up.

So, best practice is to use the same error code for all kinds of errors, that way nobody will ever be able to tell the difference between errors? At least looking up error codes won't be needed. :rolleyes:


All times are GMT -5. The time now is 03:06 AM.