Solved

bash-script: variable variable

Posted on 2002-05-23
3
677 Views
Last Modified: 2006-11-17
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?
0
Comment
Question by:huxun
  • 2
3 Comments
 

Expert Comment

by:jolbe13
ID: 7029913
I usually solve this kind of problem with arrays. If you are not familiar with arrays I can write you an example.
0
 

Accepted Solution

by:
jolbe13 earned 50 total points
ID: 7029928
I would write it like that :

#!/bin/bash
# declare array
declare -a i

# set array values
i[1]="193 4 0 0 16"
i[2]="194 144 0 0 16"

count=2
cur=0

n=0
while [ $n -lt $count ]
do
  let n=$n+1
  cur=${i[$n]}
  echo $cur
done

Hope this help.
0
 

Author Comment

by:huxun
ID: 7030023
Yeah ... I thought of an array, but didn't think bash would support them.

Well, I was wrong :|

Thanks!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question