Solved

bash-script: variable variable

Posted on 2002-05-23
3
675 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
Comment Utility
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
Comment Utility
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
Comment Utility
Yeah ... I thought of an array, but didn't think bash would support them.

Well, I was wrong :|

Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now