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.
exitto control the exit code;
mainis the exit code;
System.Exitto control the exit code from the
Copyright © 2020-2023 Rudy Matela
All rights reserved