RafaelGP
RafaelGP

Reputation: 1889

Bash - Echo a variable using another variable (?)

Thank you very much in advance for helping!

I have this variables:

scene1=lounge
scene2=bedroom
scene3=bathroom

What I want to do is a loop, and for every file in a particular folder, echo the variable scene#

order=1
for f in $(find $dest_scenes/*.xml -maxdepth 0 )
do
    scene_name=scene$order #scene1, scene2, scene3
    echo $scene_name
done
order=$(expr $order + 1)

Output:

scene1
scene2
scene3

What I would like to:

lounge
bedroom
bathroom

I don't want to get $scene_name, I want to got $($scene_name) if you know what I mean...

Thank you!!!

Upvotes: 0

Views: 643

Answers (1)

Mat
Mat

Reputation: 206689

That's called variable interpolation. In your case, you could do:

echo ${!scene_name}

See How do I use a variable within a variable for more variations.

Upvotes: 2

Related Questions