I am trying to map a hostname to a queue manager name using the following array. I get an error with bad array script. What am I doing wrong here
declare -A managers
while read -r mgr host; do
managers[$mgr]=$host
done < file.txt
QMGR=$(cat qmgr.txt)
host=${managers[$QMGR]}
I get the following error:
Bad array sub script at line 3
doneis on the same line as themanagersassignment, the syntax is fairly broken. If not: What is the value ofmgrat this point? Easiest way to find out might beset -x. By the way, I get "bad array subscript" when the subscript is empty. Is this your error?shellcheck.net. (b) Quote all variable expansions. (c) Show us the input files. (d) Print every variable immediately it changes, preferably like:declare -p managers. (e) Do you have a shebang? (f) The only subscript operation is not on line 3, so you are not showing us the script you are running.