Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: unix shell script question
Something else for people who are bored:
If I may ASS-U-ME that your ultimate goal is to have variables like:
LINE_THIS LINE_THAT LINE_THE_OTHER_THING
and you want to be able to change what is after the LINE part, if you have genuine ksh93, and you like playing around with scripting stuff, then you can try playing around with associative arrays. For example:
LINE=([THIS]='ABC' [THAT]='XYZ' [THE_OTHER_THING]='HELLO WORLD')
X='THE_OTHER_THING'
echo ${LINE[$X]}
HELLO WORLD
X='THIS'
echo ${LINE[$X]}
ABC
X='THAT'
echo ${LINE[$X]}
XYZ
I think you must define the associative array as a single command; i.e. you
can't do
LINE=([THIS]='ABC')
LINE=([THAT]='XYZ')
because you will only have ${LINE[THAT]}
Note that, as far as I know, this stuff works only with ksh93. Ksh88 is probably much more predominant on non-Linux, and I think pdksh (public domain ksh) -- which is useless for scripting -- shows up on Linux. But you can download and build ksh93. Make sure you put the (){}[] characters in the right places.
> -----Original Message-----
>
> Hi List,
>
> The requirement is as follows:
>
> DBNAME=PROD ( 'DBNAME' variable contains value 'PROD' )
>
> LINE_PROD=100 ( 'LINE_PROD' variable contains value 100 )
>
> Now I want to echo the LINE_PROD variable using DBNAME variable.
> e.g
> echo ${LINE_${DBNAME}} should return 100.
>
> Is this possible and if yes, how ? I tried some ways but
Received on Tue Jul 15 2003 - 09:14:33 CDT
![]() |
![]() |