Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    2

    Question Unanswered: 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

  2. #2
    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> |
    +-----------------------+

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •