huxun
asked on
bash-script: variable variable
Hi!
I'm trying to get this:
-------------------------- -
#!/bin/bash
i1="193 4 0 0 16"
i2="194 144 0 0 16"
count=2
cur=0
n=0
while [ $n -ln $count ]; do
let n=n+1
cur=i$n
echo $[$cur]
done
-------------------------- ---
to echo this:
-------------------------- ---
193 4 0 0 16
194 144 0 0 16
-------------------------- ---
but I only get this error:
193 4 0 0 16: syntax error in expression (error token is "4 0 0 16")
and then it terminates. Any ideas how to make this work?
I'm trying to get this:
--------------------------
#!/bin/bash
i1="193 4 0 0 16"
i2="194 144 0 0 16"
count=2
cur=0
n=0
while [ $n -ln $count ]; do
let n=n+1
cur=i$n
echo $[$cur]
done
--------------------------
to echo this:
--------------------------
193 4 0 0 16
194 144 0 0 16
--------------------------
but I only get this error:
193 4 0 0 16: syntax error in expression (error token is "4 0 0 16")
and then it terminates. Any ideas how to make this work?
I usually solve this kind of problem with arrays. If you are not familiar with arrays I can write you an example.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah ... I thought of an array, but didn't think bash would support them.
Well, I was wrong :|
Thanks!
Well, I was wrong :|
Thanks!