0

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
5
  • If the done is on the same line as the managers assignment, the syntax is fairly broken. If not: What is the value of mgr at this point? Easiest way to find out might be set -x. By the way, I get "bad array subscript" when the subscript is empty. Is this your error? Commented Jul 29, 2021 at 5:00
  • Thats was formatting error(done line). Ues bad array subscript is my error Commented Jul 29, 2021 at 5:09
  • 1
    Most likely, the subscript is empty. Commented Jul 29, 2021 at 5:49
  • 2
    Show us an example input which reproduces this error. Commented Jul 29, 2021 at 5:56
  • 2
    (a) See 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. Commented Jul 29, 2021 at 8:26

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.