Error message output

Polytropon freebsd at edvax.de
Sun Sep 20 18:28:07 UTC 2020


On Sun, 20 Sep 2020 11:19:32 -0700, Michael Sierchio wrote:
> If you know something about the error, don't just exit with any return
> value.
> 
> *>* man sysexits

Yes, I know about that (and I tend to use it in C programs);
my examples simply contained "exit 1" as opposed to explicit
or implicit "exit 0" to _at least_ signal to the caller that
there was some error. Of course being specific with an error
code from sysexits, especially using the nice EX_* values,
is convenient from C code, but requires looking them up in
the manual in case of a sh script. :-)

I fully agree that there is nothing wrong with something
like:

	if [ "$1" = "" ]; then
		echo "Error: Missing filename." > /dev/stderr
		exit 64
	fi

For C code, there are also the values EXIT_SUCCESS and
EXIT_FAILURE in stdlib.h with values 0 and 1 respectively,
in case sysexits.h should not be available.



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list