0
p=0
array="host_01"
HostProjects[$p]="project_01"
AvgCr=1569.22
eval "${array}_${HostProjects[$p]}=$AvgCr"
echo "Host Credit is ${host_01_project_01}"

Gives me 1569.22

But how can I get the result 1569.22 from:

printf '%s\n' "${array}_${HostProjects[$p]}"
or even from:
echo "${array}_${HostProjects[$p]}"

Which gives me host_01_project_01

I have tried several things but it ends up in syntax errors. Thanks.

1 Answer 1

1

If you're using Bash, indirect parameter expansion is your friend:

varname="${array}_${HostProjects[$p]}"
echo "The value you want is ${!varname}"
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.