I need to make one printable variable from echo output, I wrote this code, but seems that it not work:
myArray=('hello' 'hi')
arrayName="myArray"
arrayVar=1
echo $(echo -n '${' && echo -n "$arrayName" && echo -n '[' && echo -n "$arrayVar" && echo -n ']}')
Expected output:
hello
But it prints this:
${myArray[1]}
How can I fix it?