1

In a for, I have the following:

COUNT="1"  
GEOZONE[1]="EU"  
declare -A CLIENTS_"${GEOZONE[$COUNT]}"="client1 client2"

At this point, if I would like to print ${CLIENTS_EU} it works, but how to print that by using the GEOZONE array?

I got bad substitution while trying to:

~ $ echo ${CLIENTS_${GEOZONE[$COUNT]}}
bash: ${CLIENTS_${GEOZONE[$COUNT]}}: bad substitution

And I got EU while trying to:

~ $ echo $CLIENTS_${GEOZONE[$COUNT]}
EU

I would like to get client1 client2

Thanks

1 Answer 1

1

You need to create a separate variable that will hold composite variable name:

# ccomposte variable name
var=CLIENTS_"${GEOZONE[$COUNT]}"

# assign value
declare $var="client1 client2"

# print it
echo "${!var}"

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

Comments

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.