I am trying to print a filename which contains decimal point numbers... say
L2.3stop.txt
I have variables defined as :
z1=2.3
z2=3.4
z3=7.8
z4=8.9
and so on
In a for loop i runs from 1 to 5
Inside the loop if I do
temp=`echo z$i`
and then I print the file name using
echo L${temp}stop.txt
it just prints
Lz1stop.txt
Lz2stop.txt
etc..
How can I print the desired filename....
I also tried using
echo L$((z$i))stop.txt
but this only works when z1, z2, z3 etc are integers and not floating numbers....
I hope this helps:
z1=2.3
z2=3.4
z3=7.8
z4=8.9
for i in {1..4};do
echo L$(eval "echo \$z"$i)stop.txt
done
or this should work too:
for i in {1..4};do
echo L$(echo $(echo "\$z$i"))stop.txt
done
outputs:
L2.3stop.txt
L3.4stop.txt
L7.8stop.txt
L8.9stop.txt
This is not portable, but in bash you can do:
name=z$i
echo ${!name}
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