Associative arrays (Bash)
Versie door Jeroen Strompf (overleg | bijdragen) op 28 sep 2022 om 17:08 (Nieuwe pagina aangemaakt met '* ''Associative arrays'' are arrays where you can give elements their own name. You can also use them for multi-dimensional arrays * Associative arrays are new in B...')
- Associative arrays are arrays where you can give elements their own name. You can also use them for multi-dimensional arrays
- Associative arrays are new in Bash 4. To verify which version of Bash you have:
bash --version
Numerical index
Example:
declare -A arr arr[0,0,0]="000" arr[0,0,1]="001" arr[0,1,0]="010" arr[0,1,1]="011" arr[1,0,0]="100" arr[1,0,1]="101" arr[1,1,0]="110" arr[1,1,1]="111" echo "${arr[0,0,0]} ${arr[0,0,1]} ${arr[0,1,0]} ${arr[0,1,1]}" echo "${arr[1,0,0]} ${arr[1,0,1]} ${arr[1,1,0]} ${arr[1,1,1]}"
Associative index
declare -A device device["Alternator"]="Alternators" device["Blower"]="Blowers"