svn commit: r483437 - in head/mail/dovecot: . files

Mathieu Arnold mat at FreeBSD.org
Sat Nov 3 12:04:47 UTC 2018


On Fri, Nov 02, 2018 at 04:41:47PM -0500, Larry Rosenman wrote:
> On Wed, Oct 31, 2018 at 04:02:52PM +0100, Mathieu Arnold wrote:
> > On Mon, Oct 29, 2018 at 11:28:27PM +0000, Larry Rosenman wrote:
> > > Modified: head/mail/dovecot/files/dovecot.in
> > > ==============================================================================
> > > --- head/mail/dovecot/files/dovecot.in	Mon Oct 29 23:25:58 2018	(r483436)
> > > +++ head/mail/dovecot/files/dovecot.in	Mon Oct 29 23:28:26 2018	(r483437)
> > > @@ -60,6 +60,14 @@ for config in ${dovecot_config}; do
> > >  	required_files="${config}"
> > >  	command_args="-c ${config}"
> > >  	if [ -s ${config} ]; then
> > > +               ${command} ${command_args} -a 2>/dev/null
> > > +                if [ $? -ne 0 ]; then
> > 
> > Never test for $?.  This should be:

I should have said "never test for $? (not) being 0".

> > 
> > if ${command} ${command_args} -a 2>/dev/null; then
> > 
> > All the rationale in https://github.com/koalaman/shellcheck/wiki/SC2181.
> But, for my own interest, what if I want to put out what the return code
> is in a message?

Shell is pretty limited in term of error control.  You can write:

if foo; then
  # Before anything else, save $?
  error=$?
  # do stuff and use $error when needed.
fi

Note that $? can get cloberred by many other things that the command you
run, it can be a redirection error, a shell syntax error in the command in the
if, almost too many things to count.

-- 
Mathieu Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 963 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-ports-all/attachments/20181103/1ffb3aa8/attachment.sig>


More information about the svn-ports-all mailing list