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.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-19-2006
Registered User
 

Join Date: Aug 2006
Posts: 18
Can you have var$1 ?

Hi all,

I'm trying to assign values to multiple variables, is there a way i can just change the number of the variable? ie

read$num=YES
write$num=NO
ex$num=YES

where the $num can be changed ie. in this instance i have 3 read variables, 3 write variables and 3 ex variables and i'd prefer not to have

read1=YES
read2=YES
read3=NO
write1=NO .... etc.

Oliver
Reply With Quote
Forum Sponsor
  #2  
Old 08-20-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Yes. You might want to do something like this so it's obvious what you're doing - you'll be amazed how confused you can be looking at code again after two years...

Code:
read"$num"=somevalue
The quotes do not change anything but make it really obvious. Also using names like for variables is VERY bad idea. Don't use variable names that are also commands or shell-builtins.

You do know that ksh supports arrays
Code:
set -A  Readvar  0 0 0
set -A  Writevar 0 0 0
Now you can reference them:
Code:
echo "${Readvar[2]}"
quick explanation of arrays:
http://www.livefirelabs.com/unix_tip...3/11102003.htm
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:15 PM.


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