The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 08:39 AM
Passing a unix variable value to a Plsql function cobroraj UNIX for Advanced & Expert Users 1 10-30-2007 02:59 AM
passing variable to function Knotty UNIX for Dummies Questions & Answers 4 04-04-2007 09:49 PM
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
Passing a variable name to be created within a function 435 Gavea Shell Programming and Scripting 2 02-04-2004 11:20 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-14-2008
Registered User
 

Join Date: Jan 2008
Location: Virginia
Posts: 2
Question passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function.

sample code below
--------------
for x in 1 9
do
check_null $C$x ##call function to check if the value is null
if [ $? -eq 1 ]
then
echo "line number:$var_cnt, message: field is not null"
fi
done
--------------
C1 has a value, as does C9

I need to pass values stored in C1 and C9 to the function

Any help would be highly appreciated.

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-14-2008
Registered User
 

Join Date: Oct 2007
Posts: 153
Ah, you want the shell to parse "$C$x" as "$C1" but instead it is doing "$C" + "$x". So, you need to force it to evaluate $x first.

Code:
# C1=abc
# x=1 
# echo $C$x
1
# eval echo \$C$x
abc
Is that what you were looking for?
Reply With Quote
  #3 (permalink)  
Old 01-14-2008
Registered User
 

Join Date: Jan 2008
Location: Virginia
Posts: 2
Quote:
Originally Posted by gus2000 View Post
Ah, you want the shell to parse "$C$x" as "$C1" but instead it is doing "$C" + "$x". So, you need to force it to evaluate $x first.

Code:
# C1=abc
# x=1 
# echo $C$x
1
# eval echo \$C$x
abc
Is that what you were looking for?
Yes, I believe thats the way to do it, but how to call the function using the above ? (BTW, thanks for your post)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:30 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 Global Fact Book

Content Relevant URLs by vBSEO 3.2.0