Thread (6 messages) flat view 6 messages, 5 authors, 2019-01-03

Re: [PATCH] test-lib: check Bash version for '-x' without using shell arrays

From: Johannes Sixt <hidden>
Date: 2019-01-02 00:24:55

Am 02.01.19 um 00:19 schrieb SZEDER Gábor:
Alas, it has been reported that NetBSD's /bin/sh does complain about
them:

   ./test-lib.sh: 327: Syntax error: Bad substitution

where line 327 contains the first ${BASH_VERSINFO[0]} array access.
quoted hunk ↗ jump to hunk
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 0f1faa24b2..f47a191e3b 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -324,9 +324,12 @@ do
  		# isn't executed with a suitable Bash version.
  		if test -z "$test_untraceable" || {
  		     test -n "$BASH_VERSION" && {
-		       test ${BASH_VERSINFO[0]} -gt 4 || {
-			 test ${BASH_VERSINFO[0]} -eq 4 &&
-			 test ${BASH_VERSINFO[1]} -ge 1
+		       bash_major=${BASH_VERSION%%.*}
+		       bash_minor=${BASH_VERSION#*.}
+		       bash_minor=${bash_minor%%.*}
+		       test $bash_major -gt 4 || {
+			 test $bash_major -eq 4 &&
+			 test $bash_minor -ge 1
  		       }
  		     }
  		   }
Would it perhaps be simpler to just hide the syntax behind eval? Like

  		if test -z "$test_untraceable" || {
  		     test -n "$BASH_VERSION" && eval '
		       test ${BASH_VERSINFO[0]} -gt 4 || {
			 test ${BASH_VERSINFO[0]} -eq 4 &&
			 test ${BASH_VERSINFO[1]} -ge 1
		       }
  		     '

-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help