#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    1
    Rep Power
    0

    Post getting a ksh variable value


    Hi everybody!
    I need some help with this...
    I have those 3 variables defined on ksh:

    VAR=TONTO
    NUM=1
    TONTO1=OK

    I'd like to obtain TONTO1's value but using VAR and NUM.

    If I do:

    echo ${VAR${NUM}}

    It returns (on HP UX):

    sh: ${VAR${NUM}}: The specified substitution is not valid for this command.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    121
    Rep Power
    11
    You will need to use eval but be aware that this leads to tricky syntax especially with complex commands.

    eval echo \$${VAR}${NUM}

    This makes ksh parse the command twice. On the first pass the backslash stops ksh from trying to expand the following $, but the backslash is removed. Also on the first pass, ${VAR} and ${NUM} are expanded.

    On the second pass, it looks like:
    echo $TONTO1

IMN logo majestic logo threadwatch logo seochat tools logo