Bash 4 associative arrays
Sunday, June 14th, 2009 by Gary Richards - Categories: Linux, Operating Systems, ScriptingWhen scripting Bash, i’ve often come across problems where using an associative array would make things so much cleaner. Unfortunately Bash has never supported then…. Until now.
With Bash4 I can do this:
#!/bin/bash
declare -A info
info[blah]="Blah"
info[test]="Test"
echo ${info[blah]}
echo ${info[test]}
As you can see, associative arrays are where you use strings as the index of the array, rather than integers. Very useful.