[pacman-dev] [PATCH] Refactor lint_source to work with earlier versions of Bash

Aaron Campbell aaron at monkey.org
Wed Nov 4 19:43:12 UTC 2015


Negative subscripts to indexed arrays are not supported before 4.2.  However,
since substring expansion works on arrays, we can specify an offset of -1 to
be taken relative to one greater than the maximum index of the specified
array (see Parameter Expansion section of the bash man page).  This works with
both Bash 4.1 and 4.2, and 4.1 is already the oldest supported by pacman.

Signed-off-by: Aaron Campbell <aaron at monkey.org>
---
 scripts/libmakepkg/lint_pkgbuild/source.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/libmakepkg/lint_pkgbuild/source.sh.in b/scripts/libmakepkg/lint_pkgbuild/source.sh.in
index c327299..b5f4586 100644
--- a/scripts/libmakepkg/lint_pkgbuild/source.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/source.sh.in
@@ -32,7 +32,7 @@ lint_pkgbuild_functions+=('lint_source')
 lint_source() {
 	local idx=("${!source[@]}")
 
-	if (( ${#source[*]} > 0 && (idx[-1] + 1) != ${#source[*]} )); then
+	if (( ${#source[*]} > 0 && (${idx[@]: -1} + 1) != ${#source[*]} )); then
 		error "$(gettext "Sparse arrays are not allowed for source")"
 		return 1
 	fi
-- 
2.5.0


More information about the pacman-dev mailing list