From a1b912c9d611227b3b73337b511e91c5a0cac9e0 Mon Sep 17 00:00:00 2001 From: Andy Chu Date: Mon, 9 Mar 2020 13:02:54 -0700 Subject: [PATCH] [spec/dparen] Example of assoc array usage in (( )) Works in both bash and osh. Related to discussion on #648. --- spec/dparen.test.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/dparen.test.sh b/spec/dparen.test.sh index de5144fdf7..752a2acbf4 100644 --- a/spec/dparen.test.sh +++ b/spec/dparen.test.sh @@ -184,3 +184,20 @@ echo $x 0 ## END +#### Example of incrementing associative array entry with var key (ble.sh) +declare -A A=(['foo']=42) +key='foo' + +# note: in bash, (( A[\$key] += 1 )) works the same way. + +set -- 1 2 +(( A[$key] += $2 )) + +echo foo=${A['foo']} + +## STDOUT: +foo=44 +## END +## N-I mksh/zsh status: 1 +## N-I mksh/zsh stdout-json: "" +