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

The SDK directory does not exist (ubuntu 16.04) (react native) -

python - How to clone or copy a list? -

string - Using python and postgres, variables within execute function? -