DEV Community

Esron Silva
Esron Silva

Posted on

Why the standard exit code for a shell program is zero?

I mean, zero is equivalent to false in C language. So, why use zero as the code for a valid output in a command?

Top comments (2)

Collapse
 
alohci profile image
Nicholas Stimpson

Because there's generally only a need for one "OK" code, but lots of "ERROR" codes. So when cast to boolean you've got just OK or ERROR, but if you want more detail about the error, the information's there as an int.

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

And extrapolating from this, the most logical value for representing that singular success case with an integer is zero, because it doesn't care one bit (no punt intended) about what type of integer it is (zero is zero, regardless of bit width, bit or byte order, or whether it's signed or not).