Skip to content
Advertisement

How to echo a dynamic variable’s content in shell script

How to echo a dynamic variable’s content in shell script ?

i=1
declare  x$i=help
echo  $(echo x$i)
echo $x$i

Current output:

x1  
1

Desired output:

help

Advertisement

Answer

Use eval:

i=1
declare  x$i=help
eval "echo $x$i"
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement