UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old December 17th, 2003, 04:27 AM
norahgarb norahgarb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 norahgarb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #2  
Old December 17th, 2003, 06:15 AM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > getting a ksh variable value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway