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 return 1
Also, from shell-tips:
$ expr 1 / 0 expr: division by zero $ echo $? 2
ls nosuchfilefor the illustration, by the way. Or if I want to show how non-zero exit statuses do have conventional meanings, I would set up as follows:echo hello > file1; echo hello > file2; echo goodbye > file3and then show the exit status forcmp file1 file2,cmp file1 file3,cmp file1 file4.