Syntax error in a script...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Syntax error in a script...
# 1  
Old 12-05-2005
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
# 2  
Old 12-05-2005
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.
# 3  
Old 12-05-2005
when the query returns nothing then only its giving the error
# 4  
Old 12-05-2005
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" ]
# 5  
Old 12-05-2005
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.
# 6  
Old 12-06-2005
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
# 7  
Old 12-06-2005
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Syntax error on script

Evening All (or morning for some), Could anyone have a look at the below and advise where i've going wrong with the syntax as i keep getting the below error while trying to run. Any help would be really apprecaited. ./testout: line 13: syntax error near unexpected token `else' ... (4 Replies)
Discussion started by: mutley2202
4 Replies

2. Shell Programming and Scripting

First Script Syntax Error

So, I'm writing my first shell script to try to speed up the process of creating lyric files for mocp and I don't know what the error is, but considering how short the code is, I'm betting it's something super-obvious. line 7: syntax error near unexpected token `echo' line 7: ` echo... (4 Replies)
Discussion started by: D351
4 Replies

3. UNIX for Dummies Questions & Answers

Syntax Error Script

Hi guys i'd like to show you this code of my script, where i couldn't find this error " #! /bin/bash #copiabin.sh: copia todos los archivos ejecutables a bin if then mkdir $HOME/bin fi # copia de archivos y contador N N=0 for ARCH in * do if # Si el archivo es... (9 Replies)
Discussion started by: Newer
9 Replies

4. Shell Programming and Scripting

Syntax Error in Script

Hi All, I am new to Unix, I have written the following script in ksh and get a syntax error :wall:. I need some help to figure out the error and reason. The script below uses some variables from an environment file, also it executes a sql file. The sql file is correct and has no problems. I... (1 Reply)
Discussion started by: disshort23
1 Replies

5. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

6. Shell Programming and Scripting

Syntax error in script

Hey guys keep having problems with the below script syntax error near unpexpected token '0' exit 0 I have two directorys backups and Usr in the usr i have sub dir's wp,ss,pic which i would like to back up (copy those directorys to the backups directory) with user acknowledgement from command line.... (2 Replies)
Discussion started by: Spartukus
2 Replies

7. Shell Programming and Scripting

Syntax error with a script

Hi I not sure what is wrong with my script... when I try to run it I get the follow error: "remove: syntax error at line 77: `end of file' unexpected" Thanks in advance for any help. ans=y while do while : do echo "Please enter a name that you... (3 Replies)
Discussion started by: simpsonjr
3 Replies

8. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

9. Shell Programming and Scripting

Syntax error in script

I get this error when I try to run my script (BTW, this is a simple script I am supposed to write for my class) $ menuscript menuscript: syntax error at line 89 : `"' unmatched $ Here is the code (Any help is greatly appreciated) (Line numbers included) 1 #!/bin/ksh 2 ... (2 Replies)
Discussion started by: KindHead
2 Replies

10. Shell Programming and Scripting

syntax error in script !!

./disk_space_util.sh ./disk_space_util.sh: Syntax error at line 24 : `then' is not expected. ================================= cat disk_space_util.sh #!/bin/sh # # Parameter Settings ORA_LOG, ORA_SCRIPT, DBA_EMAIL_LIST -- (Set in .profile) bdf | sed "s/%/ /g" | sed "/Filesystem/d" |... (13 Replies)
Discussion started by: uuser
13 Replies
Login or Register to Ask a Question