Bash associative array increment value strange behavior -


i want increment value in associative array in bash, found strange behavior. if value 0 error code 1, otherwise it's 0. code snippet:

#!/bin/bash  declare -a arr  key="create|server"  arr["$key"]=0  (('arr["$key"]'++)) echo "err_code: $?" # 1, wtf  (('arr["$key"]'++)) echo "err_code: $?" # 0 

do know causes strange behavior?

post increment. expression evaluates 0 (false) , return status 1. use pre-increment:

(( ++arr["$key"] )) 

if want avoid this. expression evaluate 1 (true) , return status 0.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -