From e25e7ad50bb82b416e2c703356867a8be7cb9d09 Mon Sep 17 00:00:00 2001 From: Wynn Wolf Arbor Date: Tue, 12 May 2020 22:14:47 +0200 Subject: Simplify conditional logic in test_diff() Previously we recorded the return value of the sed ... | diff pipeline into a variable and later used it to test whether the command returned successfully or not. Since we enable errexit, this meant that the diff command failing would terminate the execution of the whole script. We are unsure how this was not caught earlier as the script has been in use for quite a while now - it is possible that bash 5.0 shows different behaviour here. It is our understanding that bash's current behaviour is correct, however. Instead of using a variable to store the return value, put the whole pipeline into an if clause, and react to its success or failure there. Whilst this does remove our ability to indicate diff's actual return value, it makes this test simpler and more straightforward. --- kern | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/kern b/kern index 9686e57..f4a8be3 100755 --- a/kern +++ b/kern @@ -85,18 +85,16 @@ clean_kernel() { test_diff() { dt=$(mktemp) zcat /proc/config.gz | sed -nE '/^(# )?CONFIG_.*/p' > "$dt" - sed -nE '/^(# )?CONFIG_.*/p' .config | diff -q "$dt" - - diffr=$? - rm -f "$dt" - if test $diffr -ne 0; then + if ! sed -nE '/^(# )?CONFIG_.*/p' .config | diff -q "$dt" -; then diff_kernel printf "Continue? [y/N] " read -r response - if test "$response" = "y"; then - return 0 + if test "$response" != "y"; then + rm "$dt" + return 1 fi fi - return $diffr + rm "$dt" } all() { -- cgit v1.2.3-2-gb3c3