For this problem I have two values, curdir and curlevel, which change throughout my script. I want to know if it's possible to create a variable and then use that value as the name for another value. For example
temp="dir_${curdir}_${curlevel}"
$temp=$name_of_directory **<----Is there a legitimate way to do this?**
so if initially curdir=1
and curlevel=0
then
$(temp)=directory_one
is equal to
dir_1_0=directory_one
then later if curdir=2
and curlevel=4
, I can reset temp and then have
$(temp)=another_directory
is the same as
dir_2_4=another_directory
so I could make a call such as
cd $(temp)
which will move me to different directories when I need to
I think what you want is to use eval
. Like so:
$ foo=bar
$ bar=baz
$ eval qux=\$$foo
$ echo $qux
baz
So what you could do is something like
eval temp=\$$"dir_${curdir}_${curlevel}"
cd $temp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With