git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] t9902-completion.sh: old Bash still does not support array+=('') notation

From
BCBrandon Casey <bcasey@nvidia.com>
Date
Aug 21, 2013, 20:49 UTC
Message-ID
<1377118173-23405-2-git-send-email-bcasey@nvidia.com>
In-Reply-To
<1377118173-23405-1-git-send-email-bcasey@nvidia.com>
From: Brandon Casey <drafnel@gmail.com>

Old Bash (3.0) which is distributed with RHEL 4.X and other ancient platforms that are still in wide use, does not understand the array+=() notation. Let's use an explicit assignment to the new array element which works everywhere, like:

   array[${#array[@]}+1]=''

The right-hand side '' is not strictly necessary, but in this case I think it is more clear.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
---
 t/t9902-completion.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 272a071..2d4beb5 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -69,7 +69,7 @@ run_completion ()
 	local -a COMPREPLY _words
 	local _cword
 	_words=( $1 )
-	test "${1: -1}" = ' ' && _words+=('')
+	test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
 	(( _cword = ${#_words[@]} - 1 ))
 	__git_wrap__git_main && print_comp
 }
-- 
1.8.4.rc0.2.g6cf5c31


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Previous: Brandon CaseyNext: Brandon Casey
Message 2 of 10 in “git-completion.bash: use correct Bash/Zsh array length syntax”
  1. 1/3 git-completion.bash: use correct Bash/Zsh array length syntaxBrandon Casey, Aug 21, 2013
  2. 2/3 t9902-completion.sh: old Bash still does not support array+=('') notationBrandon Casey, Aug 21, 2013
  3. 3/3 Revert "bash prompt: avoid command substitution when finalizing gitstring"Brandon Casey, Aug 21, 2013
  4. Junio C HamanoAug 21, 2013
  5. Brandon CaseyAug 21, 2013
  6. Junio C HamanoAug 22, 2013
  7. Brandon CaseyAug 22, 2013
  8. contrib/git-prompt.sh: handle missing 'printf -v' more gracefullyBrandon Casey, Aug 22, 2013
  9. contrib/git-prompt.sh: handle missing 'printf -v' more gracefullyBrandon Casey, Aug 22, 2013
  10. Junio C HamanoAug 22, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.