Home » Infrastructure » Unix » Substitute a variable inside a variable (HP Unix)
Substitute a variable inside a variable [message #380177] Fri, 09 January 2009 07:13 Go to next message
ganeshsv
Messages: 51
Registered: January 2006
Member
HI,
How can we substitute a variable inside another variable. Say for example

country=IN
IN_REGION=SOUTH
VALUE=${${country_REGION}

We are getting bad substitution error. How this can be achieved?

Thanks in advance,
GS
Re: Substitute a variable inside a variable [message #380180 is a reply to message #380177] Fri, 09 January 2009 07:17 Go to previous messageGo to next message
tahpush
Messages: 961
Registered: August 2006
Location: Stockholm/Sweden
Senior Member

VALUE=${country}_REGION
Re: Substitute a variable inside a variable [message #380181 is a reply to message #380177] Fri, 09 January 2009 07:18 Go to previous messageGo to next message
Frank Naude
Messages: 4420
Registered: April 1998
Senior Member
Not sure I understand what you want.
What should "echo $VALUE" return?
Re: Substitute a variable inside a variable [message #380182 is a reply to message #380181] Fri, 09 January 2009 07:21 Go to previous messageGo to next message
ganeshsv
Messages: 51
Registered: January 2006
Member
HI,
We would like to get the output in VALUE field as SOUTH.

country=IN
IN_REGION=SOUTH
VALUE=${${country}_REGION} [as $country=IN, $IN_REGION=SOUTH]

Thanks in advance,
GS
Re: Substitute a variable inside a variable [message #380188 is a reply to message #380182] Fri, 09 January 2009 07:53 Go to previous message
Frank Naude
Messages: 4420
Registered: April 1998
Senior Member
#!/bin/bash

country=IN
IN_REGION=SOUTH
eval VALUE=\${${country}_REGION}
echo VALUE=$VALUE


For more info, search "name reference variables".
Previous Topic: sqlplus: Permission denied
Next Topic: Oracle9i Library on 64-bit Solaris
Goto Forum:
  


Current Time: Wed Oct 22 08:58:02 CDT 2014

Total time taken to generate the page: 0.07020 seconds