The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 11:39 AM
Passing a unix variable value to a Plsql function cobroraj UNIX for Advanced & Expert Users 1 10-30-2007 06:59 AM
passing variable to function Knotty UNIX for Dummies Questions & Answers 4 04-05-2007 12:49 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 11:29 AM
Passing a variable name to be created within a function 435 Gavea Shell Programming and Scripting 2 02-04-2004 03:20 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-14-2008
KingVikram KingVikram is offline
Registered User
  
 

Join Date: Jan 2008
Location: Virginia
Posts: 3
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
  #2 (permalink)  
Old 01-14-2008
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
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?
  #3 (permalink)  
Old 01-14-2008
KingVikram KingVikram is offline
Registered User
  
 

Join Date: Jan 2008
Location: Virginia
Posts: 3
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)
Sponsored Links
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0