#!/bin/bash declare -rgA arr=([1234]=A1 [1235]=A2 [2345]=B1 [5678]=C2 [2346]=D5) i=0 for chip in "${!arr[@]}" do echo " var $((i++)) is $chip and version is ${arr[$chip]}" done bash --version
Standard input is empty
var 0 is 2345 and version is B1 var 1 is 2346 and version is D5 var 2 is 1234 and version is A1 var 3 is 1235 and version is A2 var 4 is 5678 and version is C2 GNU bash, version 4.4.11(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://g...content-available-to-author-only...u.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.