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
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 08:16 AM
syntax error, need to redo one line in script :( mr_manny Shell Programming and Scripting 4 01-10-2008 10:20 AM
Syntax error in script KindHead Shell Programming and Scripting 2 12-12-2006 07:28 PM
syntax error in script !! uuser Shell Programming and Scripting 13 02-15-2006 11:58 AM
problem with script and syntax error message ReV Shell Programming and Scripting 5 01-20-2006 03:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-05-2005
Registered User
 

Join Date: Feb 2005
Location: Bangalore
Posts: 36
Syntax error in a script...

Hi All,

I have been fighting with a syntax error for the last 2 days, still haven't got the solution. Could you please help me, your help will be greatly appreciated.

In my script I am getting a error in a for loop, its similar to the one as is below.

for v_id in v1 v2 v3 v4
do
v_flag=`sqlplus -s orauser/passwd@oracle_sid << oratest
set feedback off
set heading off
select 'Y' from mytable where myid = $v_id;
exit 5
oratest`
if [ $v_flag ]
then
update the o/p file
fi
done

If the condition fails in the query the v_flag is null, then its giving the error "for not matched"

Can't I use the if condition which will be null inside the for loop?


Thanks in Advance
Raju
Reply With Quote
Forum Sponsor
  #2  
Old 12-05-2005
Registered User
 

Join Date: Sep 2005
Posts: 45
I can's see any reason why not - are you sure that's the problem?

I'd echo out the value of $v_flag for each iteration and see what it actually contains. It may be that it has some unexpected value as a result of the query (such as apostrophe's or quotes) that are throwing the script.
Reply With Quote
  #3  
Old 12-05-2005
Registered User
 

Join Date: Feb 2005
Location: Bangalore
Posts: 36
when the query returns nothing then only its giving the error
Reply With Quote
  #4  
Old 12-05-2005
Registered User
 

Join Date: Sep 2005
Posts: 45
Well I'm still not convinced it's because the query's returning nothing. It sounds more like it's returning something the query can't handle, but why not try putting quotes around the variable in the test, ie:-

if [ "$v_flag" ]
Reply With Quote
  #5  
Old 12-05-2005
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
You really should add a proper test flag to the if [ $v_flag ] .. as well as putting quotes round the variable as grasper suggests.

Without any arguments the test just checks if the string contains any characters or not. If this is the test you want then write it like:

if [ -n "$v_flag" ]

The reason you have to put quotes round it is because if the string doesn't contain any characters then the command that gets run is

if [ ]

which is illegal. As opposed to

if [ "" ]

Which is what you want to be running.
Reply With Quote
  #6  
Old 12-06-2005
Registered User
 

Join Date: Feb 2005
Location: Bangalore
Posts: 36
Thanks for your immediate response.

But its still giving the same error. If I comment the for loop and executing the for a single variable then its fine, but for the "for loop" its giving the error, am checking for the alternatives if any.

Regards,
Raju
Reply With Quote
  #7  
Old 12-06-2005
Registered User
 

Join Date: Sep 2005
Posts: 45
Ok, run the script for each possible value of v_id and echo out the values of $v_flag.

Or alternatively, add the loop back, but edit it each time to run only one of the potential values of v_id and again see what the values of $v_flag are. Cut and paste them in your reply if you can.
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 12:00 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