1

Is there a way to make an array of dictionary like in python for bash?

I want to have to keep track of multiple associative arrays in bash. Is this possible?

I am reading in from a file and each line(separated by a certain character) represents different properties.

2
  • Everything is possible if you provide a concrete problem with some examples. Commented Feb 10, 2014 at 7:00
  • When you start trying to build complicated data structures, it's time to move to a different language. Commented Feb 10, 2014 at 20:59

1 Answer 1

1

You can trivially simulate nested associative arrays in flat ones by combining their keys:

declare -A array

set_value() { array[$1:$2]=$3; }
get_value() { echo "${array[$1:$2]}"; }

set_value english name "Name"
set_value fremch name "Nom"

get_value english name 

This simple example uses arrayname:keyname as key. If your array or key names can contain colons, you can choose another delimiter, or add appropriate escaping.

Sign up to request clarification or add additional context in comments.

1 Comment

This simulates using tuples for keys (array[english,name]) rather than nested arrays (array[english][name]). You can't, for example, easily retrieve the array array[english].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.