I'm trying to create an array of arrays in bash. In ruby it would something like:
projects = [
["PROJECT_ID_1", "PROJECT_TOKEN_1"],
["PROJECT_ID_2", "PROJECT_TOKEN_2"],
["PROJECT_ID_3", "PROJECT_TOKEN_3"],
["PROJECT_ID_4", "PROJECT_TOKEN_4"]
]
This obviously doesn't work in bash but I can't quite get the syntax right. I know that I'll have to do something like:
declare -a PROJECTS=()
# What goes here?
What is the correct way of doing this in bash?
project_ids=( A B C D ); project_tokens=( W X Y Z ); then:for idx in "${!project_ids[@]}"; do project_id=${project_ids[$idx}; project_token=${project_tokens[$idx]}; echo "Project with id $project_id has token $project_token"; donedeclare -A project_tokens=( [A]=W [B]=X [C]=Y [D]=Z ); then"${!project_tokens[@]}"will expand to the list of IDs, and"${project_tokens[$id]}will map an ID to a token.