Doubt about test constructs with aritmetic operations

Hello guys, i hope you can help me..

Taking for granted the fact that '0' means success and '1' means failure (in bash environment), why this code

1
2
3
4

(( 0 && 1 ))
echo $?     # 1


echoes 1 as exit status?..
I mean, the result of the logical operation is 0 (because true AND false is always false), in fact

1
2
let "num = (( 0 && 1 ))"
echo $num   # 0 


but why the exit status is 1?

same for

1
2
let "num = (( 0 && 1 ))"
echo $?     # 1 


Thank you all in advice.
Last edited on
Well true is akin to success.
1
2
3
4
$ false ; echo $?
1
$ true ; echo $?
0
Zero is success, 1 is failure.

The result of 1 means failure.

That's why C programs return zero on success.

For example: https://www.learn-c.org/en/Hello%2C_World%21
Last edited on
Topic archived. No new replies allowed.