Reading about bash at tldp.org
On testing constructs
let "1<2" returns 0 (as "1<2" expands to "1")
(( 0 && 1 )) returns 1 (as "0 && 1" expands to "0")
I understand the first parts, returns 0(true) or 1(false)
But WHY do they expand to "1" but is true or expand to "0" but is false??
I finally Registered.
Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Bash. What?? Why?
Further reading in an example.
Exit status opposite from [ ... ] construct!
Probably, take way more math then I could understand(which isn't much), to explain why the value is always opposite the true or false state.
or
Since convention says 0=True and 1=False screw the math.
No more thinking. Going to watch the boob tube.
Exit status opposite from [ ... ] construct!
Probably, take way more math then I could understand(which isn't much), to explain why the value is always opposite the true or false state.
or
Since convention says 0=True and 1=False screw the math.
No more thinking. Going to watch the boob tube.
Actually, shell convention says 0 is true and anything else is false.
This makes sense in a way that in shell you are always checking the exit code of the previously executed program. Since programs can indicate a number of errors (as why the program failed) by setting their exit code to something, these exit codes are considered as errors. So if the program indicated no error (exited with 0), it will treated as true since the previous program was successful.
Since [ is a program (it's a link to 'test', try: man [), its exit code is treated as any other program's exit code. So if the test succeeded, it will set its' exit code to 0. It it failed, the exit code will vary depending on the cause of the failure, but will always be other than 0, thus will be treated as false.
This makes sense in a way that in shell you are always checking the exit code of the previously executed program. Since programs can indicate a number of errors (as why the program failed) by setting their exit code to something, these exit codes are considered as errors. So if the program indicated no error (exited with 0), it will treated as true since the previous program was successful.
Since [ is a program (it's a link to 'test', try: man [), its exit code is treated as any other program's exit code. So if the test succeeded, it will set its' exit code to 0. It it failed, the exit code will vary depending on the cause of the failure, but will always be other than 0, thus will be treated as false.