From 27133b73f484d3cf2a94a174cc0ca695d2de7938 Mon Sep 17 00:00:00 2001 From: Karl Bartel Date: Tue, 12 Nov 2024 16:20:39 +0100 Subject: [PATCH] progress: Avoid accidental early return expr returns a non-zero exit code if it's calculated value is zero. This is surprising and usually not what you want. In this case, it will lead to the script terminating early for some values (e.g. HOURS=0). Small example to show the problem: ``` > bash -c 'HOURS=`expr 0` && echo true || echo false' false ``` Fortunately, bash has the arithmetic calculation syntax $((...)) that behaves as intended. --- progress.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/progress.sh b/progress.sh index 1e33b23..a09bacb 100755 --- a/progress.sh +++ b/progress.sh @@ -36,9 +36,9 @@ fi # How many more blocks do we need? HEAD=`cast block-number --rpc-url $L2_URL` -BEHIND=`expr $HEAD - $T1` -MINUTES=`expr $BEHIND / $PER_MIN` -HOURS=`expr $MINUTES / 60` +BEHIND=$((HEAD - T1)) +MINUTES=$((BEHIND / PER_MIN)) +HOURS=$((MINUTES / 60)) if [ $MINUTES -le 60 ] ; then echo Minutes until sync completed: $MINUTES