Syntax error in a script... [message #149847] |
Mon, 05 December 2005 05:21 |
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 |
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 |
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 |
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 #150301 is a reply to message #150298] |
Wed, 07 December 2005 01:31 |
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.
|
|
|
|