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 > strange parameter passing issue in KSH

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-24-09, 19:17
aliyesami aliyesami is offline
Registered User
 
Join Date: Jun 2003
Posts: 29
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
Reply With Quote
  #2 (permalink)  
Old 11-25-09, 05:35
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
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
Reply With Quote
  #3 (permalink)  
Old 11-25-09, 14:27
kitaman kitaman is offline
Registered User
 
Join Date: Sep 2009
Location: Ontario
Posts: 528
Try adding a backslash to the concatenated name:
$OOCEA\_INCOMING_READY
Reply With Quote
Reply

Thread Tools
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