4 ms·
Would you find it less surprising if the let command behaved differently than most other commands, and didn't stop the program if it returned a non-zero exit co
by thayne 4y ago
Would you find it less surprising if the let command behaved differently than most other commands, and didn't stop the program if it returned a non-zero exit code?
Because, this example works exactly the way I would expect. The next one (using the double parentheses syntax) is more questionable, and I could see it going either way, and would either look it up in the manual, or put an `|| true` after it to be safe. The fact that it changed in a minor release is pretty bad though.
- wodenokoto 4y agoCome again, why is `i++` obviously an error when `i` is zero? I’d expect an arithmetic operation to fail if I, say, divide by 0. Not if I add 1 to zero! And just because behavior is documented doesn’t mean it’s not surprising or complicated.
- powersnail 4y agoNot your parent commenter. I'd expect let command not to return a numeric value at all, since bash uses the returned numeric value to indicate success/failure. But that admittedly doesn't have anything to do with the design of "set -e".
- thayne 4y agolet doesn't return the numeric value of the expression as an exit code: > If the last ARG evaluates to 0, let returns 1; let returns 0 otherwise. Which allows you to do things like: while let --i; do some command; done or if let x > 4; then some command; fi