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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -