I was trying to think of a quick and illustrative way to generate a non-successful exit status and thought dividing by zero with the
bc would be a good idea.
I was suprised to discover that although it does generate a runtime error, the exit status is still 0:
$ echo 41 + 1 | bc 42 $ echo $? 0 $ echo 42/0 | bc Runtime error (func=(main), adr=6): Divide by zero $ echo $? 0
- Why does the bc utility not fail with a non-zero exit status?
Note: For a quick non-zero exit status I'm using
Also, from shell-tips:
$ expr 1 / 0 expr: division by zero $ echo $? 2