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 > 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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
getting variable inside awk subin_bala Shell Programming and Scripting 1 06-05-2008 04:21 AM
Sed , Replace a "variable text" inside of a statement jackn7 Shell Programming and Scripting 4 03-04-2008 03:40 PM
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 08:28 PM
Replace variable with a user defined variable ce124 Shell Programming and Scripting 1 04-15-2007 02:56 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 11:29 AM

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 03-21-2007
mani_um mani_um is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 30
How to replace variable inside the variable

hi sir,
i need your help for this script

Quote:
USERID=username/passwd
BILLDATE=19-FEB-07
STARTPARTNNUM=101
TOTALPARTN=20
SQLLOG=${BILLDATE}_xMNBDF045_P_CTEL.log
SCRIPT=`cat /rnmucdr/ednms05/ken/xMNBDF045_Script.sql`

sqlplus -s $USERID > $SQLLOG << EOF
WHENEVER SQLERROR EXIT 1
$SCRIPT
EOF
if [ $? -ne 0 ]
then
cat $SQLLOG
else
echo "SUCCESSFULLY FINISHED" > $SQLLOG
fi
inside /rnmucdr/ednms05/ken/xMNBDF045_Script.sql content variable like this

select * from invoice where bill_date=$BILLDATE and startNum=$STARTPARTNNUM and total_partn=$TOTALPARTN

if i just paste this replace with the $SCRIPT it works great,if i put script other place with with the variable,and put in the varaible script,it not works because the variable is not subtitute..
can anyone help me to solve this problem,i need to replace it with the parameter given here
  #2 (permalink)  
Old 03-21-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
try replacing $script by cat /rnmucdr/ednms05/ken/xMNBDF045_Script.sql

like this

Code:
USERID=username/passwd
BILLDATE=19-FEB-07
STARTPARTNNUM=101
TOTALPARTN=20
SQLLOG=${BILLDATE}_xMNBDF045_P_CTEL.log
SCRIPT=`cat /rnmucdr/ednms05/ken/xMNBDF045_Script.sql`

sqlplus -s $USERID > $SQLLOG << EOF
WHENEVER SQLERROR EXIT 1
cat /rnmucdr/ednms05/ken/xMNBDF045_Script.sql
EOF
if [ $? -ne 0 ]
then
cat $SQLLOG
else
echo "SUCCESSFULLY FINISHED" > $SQLLOG
fi
  #3 (permalink)  
Old 03-21-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Add slash
Code:
select \* from invoice where bill_date=$BILLDATE and startNum=$STARTPARTNNUM and total_partn=$TOTALPARTN
Replace
Code:
SCRIPT=`cat /rnmucdr/ednms05/ken/xMNBDF045_Script.sql`
by
Code:
SCRIPT=$( eval echo $(cat /rnmucdr/ednms05/ken/xMNBDF045_Script.sql))
  #4 (permalink)  
Old 03-21-2007
mani_um mani_um is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 30
syntax error
0403-057 Syntax error at line 1 : `(' is not expected.

for

Code:
SCRIPT=$( eval echo $(cat /rnmucdr/ednms05/ken/xMNBDF045_Script.sql))
If i do this
Code:
echo $SCRIPT
nothing display..only empty line printed
  #5 (permalink)  
Old 03-21-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
can you show the code in /rnmucdr/ednms05/ken/xMNBDF045_Script.sql?
  #6 (permalink)  
Old 03-21-2007
mani_um mani_um is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 30
here is the code

Code:
USERID=USER/pass
SCRIPTFILE=/rnmucdr/ednms05/ken/xMNBDF045_Script.sql
BILLDATE=19-FEB-07
STARTPARTNNUM=101
TOTALPARTN=20
SQLLOG=${BILLDATE}_xMNBDF045_P_CTEL.log
echo $SQLLOG
echo $SCRIPTFILE
SCRIPT=$( eval echo $(cat $SCRIPTFILE))

sqlplus -s $USERID > $SQLLOG << EOF
WHENEVER SQLERROR EXIT 1
$SCRIPT
EOF

if [ $? -ne 0 ]
then
cat $SQLLOG
else
echo "SUCCESSFULLY FINISHED" > $SQLLOG
fi
HERE IS THE SQL STAMENT /rnmucdr/ednms05/ken/xMNBDF045_Script.sql
Code:
create table acct_to_print_bak as
select BILL_DATE,ACCT_NO,STATUS_CODE,floor((ROWNUM-1)/N)+$STARTPARTNNUM BP_PARTN_NUM,SYS_APPL_ID FROM (
select T1.BILL_DATE,T1.ACCT_NO,T1.STATUS_CODE,T1.BP_PARTN_NUM,T1.SYS_APPL_ID,T3.N from acct_to_print t1,inv_acct_bill_addr T2
,(select ceil(count(*)/$TOTALPARTN) N from inv_acct_bill_addr) T3 where t2.bill_date='$BILLDATE' and t2.bill_date=t1.bill_dat
e and t1.ACCT_NO=t2.ACCT_NO order by T2.postal_code ) T4;
commit;
truncate table acct_to_print;
insert into acct_to_print (select * from acct_to_print_bak);
commit;
drop table acct_to_print_bak;
Any Idea
  #7 (permalink)  
Old 03-21-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
what's the error you are getting from my code???? And also, remember all the multiple lines will be converted to one line when assignint it to a variable.
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 09:13 PM.


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