If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Variables within variables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-05, 10:02
ddobes ddobes is offline
Registered User
 
Join Date: Jan 2005
Posts: 2
Question Variables within variables

I am currently writing a script that is going to take a list of arguments (server names) from the command line. I want to pass this list of arguments to a function, which will then take each argument (given I don't know how many args there are) and pass that on to a different function. Without boring everyone with details, can anyone help me with the following. I have allready solved it using a different method, but being competitive in nature, I HAVE to figure out if it can be done.

What I want to try to do (unsolved)
i=1
while [ $i -le $# ]
do
Serv_Info $$i
i=`expr $i + 1`
done

The easy solution to the above (I know, just use the easy way but I wan't to get it working above)

while [ $# -ne 0 ]
do
Serv_Info $1
shift
done

An example is, if the first argument is "bob" then I want to call "Serv_Info bob". The first example just evaluates $$i to "$1" I have tried various ways of quoting, backslashing, single quoting and double quoting the Serv_Info $$i line with no luck. Any help would be great but like I said I have reverted to the easy way but I like knowing the hard way of doing something
Reply With Quote
  #2 (permalink)  
Old 01-19-05, 10:26
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
#!/bin/ksh

typeset -i i=0;

while (( (i=i+1) <= $# ))
do
echo "[$i]"
done
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 01-27-05, 11:41
jmdevil jmdevil is offline
Registered User
 
Join Date: Oct 2003
Posts: 9
That did not work for me, I had to slightly change it:

Code:
#!/bin/ksh
typeset -i i=0
while (( (i=i+1) <= $# ))
do
  echo $(eval echo '$'$i)
do
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On