Home » Infrastructure » Unix » Syntax error in a script...
Syntax error in a script... [message #149847] Mon, 05 December 2005 05:21 Go to next message
rajus19
Messages: 18
Registered: September 2005
Junior Member
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
Re: Syntax error in a script... [message #149859 is a reply to message #149847] Mon, 05 December 2005 06:43 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member

Try something like this :

SQL> select * from test1;

        N1
----------
        22
        11
        33
        44
        55


now script
[oracle@localhost ~]$ cat > chk_tst.sh
for v_id in 11 22 6 55
do
v_flag=`sqlplus -s outln/outln << oratest
set feedback off
set heading off
select 'Y' from test1 where n1 = $v_id;
exit 5
oratest`
[ $v_flag ] && echo "got $v_flag"
done

[oracle@localhost ~]$ ./chk_tst.sh
got 
Y
got 
Y
got 
Y


it will not generate error when NULL.

regards,
tarun

Re: Syntax error in a script... [message #150107 is a reply to message #149859] Tue, 06 December 2005 06:24 Go to previous messageGo to next message
rajus19
Messages: 18
Registered: September 2005
Junior Member
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
Re: Syntax error in a script... [message #150109 is a reply to message #150107] Tue, 06 December 2005 06:26 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member
What error ? Can you post the exact snapshot from the screen?

The way i had shown it to you.
for me that script worked perfectly even with more values in the for loop.

Quote

[oracle@localhost ~]$ cat chk_tst.sh
for v_id in 11 22 6 55
do
v_flag=`sqlplus -s outln/outln << oratest
set feedback off
set heading off
select 'Y' from test1 where n1 = $v_id;
exit 5
oratest`
[ $v_flag ] && echo "got $v_flag $v_id"
done

[oracle@localhost ~]$ ./chk_tst.sh
got
Y 11
got
Y 22
got
Y 55


as you can see above for v_id=6 , its not generating any error nor it generates any output.

[Updated on: Tue, 06 December 2005 07:12]

Report message to a moderator

Re: Syntax error in a script... [message #150298 is a reply to message #150109] Wed, 07 December 2005 01:21 Go to previous messageGo to next message
rajus19
Messages: 18
Registered: September 2005
Junior Member
Thank you for good response.

The code is working fine when I execute in my local machine(windows) with cygwin, but its still giving error("for unmatched") if I run through telnet in my server(SunOS 5.Cool


Regards,
Raju
Re: Syntax error in a script... [message #150301 is a reply to message #150298] Wed, 07 December 2005 01:31 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member

Its not the problem of the code .
These kind of problems happens when you transfer the code from windows to *UNIX machine.

Write that code on the UNIX machine itself and then try to run it.
Re: Syntax error in a script... [message #150319 is a reply to message #150301] Wed, 07 December 2005 05:23 Go to previous message
rajus19
Messages: 18
Registered: September 2005
Junior Member
Thanks Tarun, I will do that.
Previous Topic: Oracle 9i installation on Solaris 9
Next Topic: Installation of oracle8i in solaris8
Goto Forum:
  


Current Time: Thu Apr 18 09:01:36 CDT 2024