Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

bash-script: variable variable

Posted on 2002-05-23
3
Medium Priority
?
693 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

885 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