Skip to content

Commit

Permalink
[spec/dparen] Example of assoc array usage in (( ))
Browse files Browse the repository at this point in the history
Works in both bash and osh.

Related to discussion on #648.
  • Loading branch information
Andy Chu committed Mar 9, 2020
1 parent c6b1ecd commit a1b912c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/dparen.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""

0 comments on commit a1b912c

Please sign in to comment.