The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 08:28 PM
how to merge two variable in one variable with space between them? jaydeep_sadaria Shell Programming and Scripting 2 12-15-2007 02:23 AM
Replace variable with a user defined variable ce124 Shell Programming and Scripting 1 04-15-2007 03:56 PM
Export command giving Variable Name vs the Value set for the Variable ParNone UNIX for Dummies Questions & Answers 2 04-03-2006 12:43 PM
ksh: A part of variable A's name is inside of variable B, how to update A? pa3be Shell Programming and Scripting 4 03-30-2005 12:29 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-18-2008
jb2780 jb2780 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Referencing variable using another variable

Hello, I am new to shell scripting so this might be a simple question...also, please excuse me if this is a topic discussed before.

I have declared a bunch of variables as such:
Host_1=32
Host_2=33
Host_3=34
temp=1
numUsers=4

Now, I am trying to go through a loop to access each of these variables. I have established a while loop like so:

while [ $temp -le numUsers]
do
echo "Host 1 = $Host_"$temp""
temp='expr $temp + 1'
done

Now this obviously is incorrect, as it looks for a variable called Host_ and doesn't find it, leaving me with only the value of temp being printed. Is there a way to have it so Host_1 is printed with temp=1? I looked into using an array but I figure there might be a quick solution to this.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0