Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003
    Posts
    29

    Unanswered: strange parameter passing issue in KSH

    here is the thing i am trying to do . I have a system variable called $OOCEA_INCOMING_READY, I want to be able to construct this variable name inside the script and use it. I am passing part of the variable name OOCEA as parameter but i am not able to use this variable after constructing the name , see below :
    ----------------- code a.sh ----------------------------------------------
    #!/usr/bin/ksh
    set -x
    AGENCY=$1
    AGENCY_CODE=$2
    FILE_TYPE=$3
    #
    echo \$${AGENCY}_INCOMING_READY
    ls \$${AGENCY}_INCOMING_READY
    ls $OOCEA_INCOMING_READY
    exit
    -------------------------------------------------------------------------


    ./a.sh OOCEA 05 ITRN

    + AGENCY=OOCEA
    + AGENCY_CODE=05
    + FILE_TYPE=ITRN
    + echo $OOCEA_INCOMING_READY <<<< does not work
    $OOCEA_INCOMING_READY
    + ls $OOCEA_INCOMING_READY <<<< does not work
    $OOCEA_INCOMING_READY: No such file or directory
    + ls /u02/oocea/incoming/ready <<< this works if i hard code the
    ITRN_20090430_0030.ZIP ITRN_20090430_1230.ZIP variable name .
    + exit

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by aliyesami
    I want to be able to construct this variable name inside the script and use it.
    Have a look at the following code. It sets up a variable called FRED. It then holds that variable's name in another variable called VARIABLE. It then uses eval to get to the original variable which is what you need:
    Code:
    #!/bin/ksh
    
    FRED="correct"
    VARIABLE="FRED"
    eval "echo \$${VARIABLE}"
    
    exit
    Mike

  3. #3
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Try adding a backslash to the concatenated name:
    $OOCEA\_INCOMING_READY

Posting Permissions

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