Results 1 to 4 of 4
Hi all,
I'm trying to figure out how to loop a variable inside a variable and print it out. Here is the example
for ((i=1;i<=4;i+=1)); do
echo $var$i
done
I ...
- 11-07-2007 #1Just Joined!
- Join Date
- Feb 2005
- Posts
- 37
simple bash question
Hi all,
I'm trying to figure out how to loop a variable inside a variable and print it out. Here is the example
for ((i=1;i<=4;i+=1)); do
echo $var$i
done
I can accomplish what I did above by:
echo $var1
echo $var2
echo $var3
echo $var4
I've tried many different ways to get this to work to no avail. Any suggestions?
Jon
- 11-07-2007 #2
We pretty much thrashed that to death here.
- 11-07-2007 #3Just Joined!
- Join Date
- Feb 2005
- Posts
- 37
thanks. so the answer is that you have to use arrays?
- 11-07-2007 #4
No, you probably don't have to use arrays, but that's the best way to write maintainable code.
If you don't want to use arrays, there's a suggestion in that thread about eval.


Reply With Quote