Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Mar 2005 10:33:30 +0100
From:      "David J. Weller-Fahy" <dave-lists-freebsd-questions@weller-fahy.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Scripting oddness (sh) - SOLVED (kind of)
Message-ID:  <20050325093308.GB10950@weller-fahy.com>
In-Reply-To: <20050323223723.GC75716@weller-fahy.com>
References:  <20050323193626.GH7474@weller-fahy.com> <20050323193716.GI7474@weller-fahy.com> <4241EDB9.5000107@toldme.com> <20050323223723.GC75716@weller-fahy.com>

next in thread | previous in thread | raw e-mail | index | archive | help
After some experimenting I believe that I've discovered how to fix the
problem, and the reason for it - I'd been thinking of the '&&' shortcut
as functionally identical to the if-then-fi construct.  That's obviously
(now ;) not the case.  If, as in the previous message, the following
'&&' shortcut is used:

#v+
[ -z "$RB_TEMP" ] && PKGLIST="$PKGLIST $PKG"
#v-

Then, if RB_TEMP is not of zero length, the exit status of that command
is one.  Since that command is the last performed in the
list_required_by function, the exit status of the function is one.
Because I used 'set -e' at the top of the script, any command (a
function being a complex command) that exits with a value of one halts
the execution of the script.  However, if we change that line to:

#v+
if [ -z "$RB_TEMP" ] ; then
	PKGLIST="$PKGLIST $PKG"
fi
#v-

Then, following the fi, the exit status is zero for both the command and
the function, and all following commands are executed.  The following
also works:

#v+
[ ! -z "$RB_TEMP" ] || PKGLIST="$PKGLIST $PKG"
#v-

Because the exit status of the first command on the line is zero if
RB_TEMP is not zero length.

So, there's a fix for it.  Figured I'd post this FTR, just in case
someone else has a lack of brain bytes similar to mine. ;]

Regards,
-- 
dave [ please don't CC me ]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050325093308.GB10950>