Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Sep 2020 23:26:55 +0530
From:      Manish Jain <bourne.identity@hotmail.com>
To:        Polytropon <freebsd@edvax.de>, FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: Error message output
Message-ID:  <DB8PR06MB64420EDA7DE039284833F648F63D0@DB8PR06MB6442.eurprd06.prod.outlook.com>
In-Reply-To: <20200920191108.22864e5c.freebsd@edvax.de>
References:  <20200920191108.22864e5c.freebsd@edvax.de>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help


On 2020-09-20 22:41, Polytropon 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?
> 
> 

Fully valid. Whenever I write any C code, those are the guidelines I 
adhere to myself.

Regards,
Manish Jain




Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?DB8PR06MB64420EDA7DE039284833F648F63D0>