[LEDE-DEV] [patch master 05/15] Use cd ... || exit in case cd fails

Oswald Buddenhagen oswald.buddenhagen at gmx.de
Sat Oct 1 00:53:13 PDT 2016


On Sat, Oct 01, 2016 at 12:05:16AM +0200, Lars Kruse wrote:
> Am Fri, 30 Sep 2016 22:02:19 +0200 schrieb Jan-Tarek Butt <tarek at ring0.de>:
> > -				libdirs="$libdirs $(cd "$libdir"; pwd)/"
> > +				libdirs="$libdirs $(cd "$libdir" || exit;
> > pwd)/" fi
> 
> I am not sure, if this script is supposed to break on every missing libdir (I
> do not know the context). Thus maybe " && " would be better instead ";"?
>
note that all cases in this patch (except those i pointed out in the
other mail) are commands within $() or (), i.e., subshells. thus, the
exit calls all only exit that respective scope.
and it's true that in most cases using '&&' instead of '|| exit;' would
be more elegant.

another implication of that is that complete error handling would imply
a lot more "visual noise". e.g.:

libdirs="$libdirs $(cd "$libdir" && pwd)/" || exit

(this assumes that the exit code of the nested command persists through
the assignment, which it is supposed to do).




More information about the Lede-dev mailing list