~xnox/debian-cd/unbreak-s390x

Viewing all changes in revision 2101.

  • Committer: Iain Lane
  • Date: 2020-12-01 11:17:30 UTC
  • Revision ID: iain.lane@canonical.com-20201201111730-oxsv7or8e72hvjww
common.sh: Use a proper "if" statement for ubuntu-canary in default_kernel_params()

In Bash (and POSIX shell), functions return the return code of the last
statement they executed if there's no other explicit return.

We have a function which ends with a statement like:

  [ $VAR = foo ] && do_something

When the first clause fails, the return code of this statement is 1. The
function returns 1 and, since we are running under set -e, the caller fails and
the script terminates.

Fix this by rewriting to use "if ... then ... fi" instead, which returns 0 if
the condition fails.

For information, note that there is a special case in the spec:

  The -e setting shall be ignored when executing [...] any command of an AND-OR
  list other than the last.

Which is why we terminate at the *caller* and not inside the function, and also
why this would work if we weren't inside a function. By being inside a
function, we effectively defeat this check.

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: