Associative Arrays in Bash v4

One of the new features in Bash v4 are the associative arrays using strings as index instead numbers
here a small example of use

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
#!/bin/bash
 
declare -A myArray #declare array
myArray[cat]=gato #attach a value into index cat
myArray[dog]=can #attach a value into index dog
 
creature="fish" #declare a variable
 
myArray[$creature]=peixe #attach a value into index fish
 
#get all array values
for key in "${!myArray[@]}"
 do
 echo "index value=$key content value= ${myArray[$key]}"
 done

Boolean and numerical values equivalence in bash

One of the problems using bash is the numeric equivalence of boolean values

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
 function zero()
 {
 return 0
 }
 
function one()
 {
 return 1
 }
 
#main section
 if zero ;
 then
 echo "0 is true"
 fi
 if one ;
 then
 echo "1 is true"
 fi

and the output is:
0 is true