Solved

bash-script: variable variable

Posted on 2002-05-23
3
687 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 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

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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

636 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