Your confusion stems from the fact that many popular languages (especially C-based ones) stop evaluating
&& sequences when 0 is encountered, because 0 is considered
false and everything else is
true. In Bash, however, that's not
Your confusion stems from the fact that many popular languages (especially C-based ones) stop evaluating
&& sequences when 0 is encountered, because 0 is considered
false and everything else is
true. In Bash, however, that's not the case. By convention, in POSIX systems (and all other Unix-like systems), return code 0 is considered
SUCCESS (there was no error, so nothing is returned) and a non-zero return code is considered
FAILURE. Every command in Bash, be it an external program such as a C program or a shell builtin, must return a value:
A simple command is a sequence of optional variable assignments
followed by blank-separated words and redirections, and
terminated by a control operator. The first word specifies the
command to be executed, and is passed as argument zero. The
remaining words are passed as arguments to the invoked command.
The return value of a simple command is its exit status, or
128+n if the command is terminated by signal n