The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 05:28 PM
How to replace variable inside the variable mani_um Shell Programming and Scripting 31 08-09-2007 07:56 PM
Replace variable with a user defined variable ce124 Shell Programming and Scripting 1 04-15-2007 11:56 AM
Export command giving Variable Name vs the Value set for the Variable ParNone UNIX for Dummies Questions & Answers 2 04-03-2006 08:43 AM
ksh: A part of variable A's name is inside of variable B, how to update A? pa3be Shell Programming and Scripting 4 03-30-2005 08:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-14-2007
Smoker's Avatar
Registered User
 

Join Date: May 2005
Posts: 12
variable as variable name (ksh)

Greetings folks

I'm using ksh on aix and have gone around and around trying to use a variable as a variable name. I would like to set a variable like this...

ym200702="01 02 05 06 07 08 09 12 13 14 15 16 19 20 21 22 23 26 27 28"

and then check to see if the variable has value...

if [[ ! -z "ym$YEAR$MONTH" ]]; then
echo HIT
fi

and if so I would like to set another variable to the contents of $ym200702.

For instance
someVariable=ym$YEAR$MONTH

I would like to stick with using ksh but if there are other ideas with sed/awk/perl etc let me know.

Smoker
Reply With Quote
Forum Sponsor
  #2  
Old 02-14-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
Code:
eval someVariable=\$ym$YEAR$MONTH
if [[ ! -z "$someVariable" ]]; then
echo HIT
fi

jean-Pierre.
Reply With Quote
  #3  
Old 02-15-2007
Smoker's Avatar
Registered User
 

Join Date: May 2005
Posts: 12
Thank You jean-Pierre

Smoker
Reply With Quote
  #4  
Old 05-16-2008
Registered User
 

Join Date: May 2008
Posts: 1
Good input Jean-Pierre! I was looking for a solution for this problem too. A Google search brings me to here. Thanks a lot and cheers with a Premier Grand Cru Classé!

Best regards,
Luis Santos
Reply With Quote
  #5  
Old 05-16-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,059
If you are using ksh93, you could also use a name reference (typeset -n) instead of eval:
Code:
#!/usr/bin/ksh93

YEAR=2007
MONTH=02

ym200702="01 02 05 06 07 08 09 12 13 14 15 16 19 20 21 22 23 26 27 28"

typeset -n someVariable="ym$YEAR$MONTH"

if [[ ! -z $someVariable ]]; then
   echo HIT
fi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0