Write a program that reads a single integer from standard input. If the integer is negative, the program should exit with an error exit code (different than zero). If the integer is zero or positive, the program should exit with a success exit code (zero).
$ ./errxit && echo 'Ok'
-3
$ ./errxit && echo 'Ok'
3
Ok
You can check the exit code from the command line by issuing the echo $?
command
or alternatively by running your program followed by && echo 'zero exit code'
which is executed when the program returns 0.
exit
to control the exit code;return
in main
is the exit code;exitSuccess
and exitFailure
from System.Exit
to control the exit code from the IO
monad.try next: bytes2bits bits2bytes
Copyright © 2020-2023 Rudy Matela
All rights reserved