Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

bash-script: variable variable

Posted on 2002-05-23
3
Medium Priority
?
690 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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,…
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.
Suggested Courses

670 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