Error message output

Michael Sierchio kudzu at tenebras.com
Sun Sep 20 18:20:11 UTC 2020


If you know something about the error, don't just exit with any return
value.

*>* man sysexits

On Sun, Sep 20, 2020 at 10:11 AM Polytropon <freebsd at edvax.de> wrote:

> I have a general question. Is it still considered useful to
> output error messages of a script to standard error?
>
> Example:
>
>         if [ something not okay ]; then
>                 echo "the error message" > /dev/stderr
>                 exit 1
>         fi
>
> While progress messages will per default go to standard output,
> error messages should be printed to standard error. The reason:
> If a program is silenced to > /dev/null, error messages will
> still be visible (no "silent failing"); if a user wants to
> explicitely mute all messages, > /dev/null 2>&1 has to be
> specified for the redirection. The judgement if a message is
> a regular progress message, an information about some slightly
> problematic case, or a real fatal error depends on the programmer.
> For example:
>
>         echo "${FILE] processed, ${RECS} records counted."
>          -> standard output
>
>         echo "${DIR} already checked, skipping."
>          -> standard output (non-fatal error"
>
>         echo "${DEV} is read only, aborting."
>         exit 1
>          -> standard error (fatal error)
>
>         echo "Cannot start: Input filename missing."
>         usage()
>         exit 1
>          -> standard error (fatal error)
>
> At least that's what I've learned centuries ago.
>
> Is that still valid?
>
>
>
> --
> Polytropon
> Magdeburg, Germany
> Happy FreeBSD user since 4.0
> Andra moi ennepe, Mousa, ...
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscribe at freebsd.org"
>


-- 

"Well," Brahmā said, "even after ten thousand explanations, a fool is no
wiser, but an intelligent person requires only two thousand five hundred."

- The Mahābhārata


More information about the freebsd-questions mailing list