Operating System - HP-UX
1829944 Members
2299 Online
109998 Solutions
New Discussion

<< symbol causes error in a loop

 
SOLVED
Go to solution
Tim Medford
Valued Contributor

<< symbol causes error in a loop

I have a very simple shell script that connects to oracle and runs a procedure. I need to run the procedure multiple times, so I'm trying to put it in a loop. Every time I try this it chokes on the <
This works ok:
#!/usr/bin/sh

export ORACLE_SID=$1

thetime=`date +%X`
sqlplus -s "/ as sysdba" <exec time_kicker ('$thetime');
!sleep 5
!thetime=`date +%X`
exec time_kicker ('$thetime');
!sleep 5
!thetime=`date +%X`
exec time_kicker ('$thetime');
!sleep 5
!thetime=`date +%X`
quit

All I'm trying to do is run time_kicker 3 times so I put it in a loop:

#!/usr/bin/sh

export ORACLE_SID=$1

for i in 1 2 3
do
thetime=`date +%X`
sqlplus -s "/ as sysdba" <exec time_kicker ('$thetime');
!sleep 5
quit
!
done

Running this script results in "Syntax error at line 8 : `<<' is not matched"

Any ideas why that won't work in a do-done loop?

Thanks, Tim
3 REPLIES 3
Alan Meyer_4
Respected Contributor
Solution

Re: << symbol causes error in a loop

you need to place the EOF end marker in the script

for i in 1 2 3
do
thetime=`date +%X`
sqlplus -s "/ as sysdba" <exec time_kicker ('$thetime');
!sleep 5
quit
!
EOF
done
" I may not be certified, but I am certifiable... "
Tim Medford
Valued Contributor

Re: << symbol causes error in a loop

That did it Alan, thanks.
Tim Nelson
Honored Contributor

Re: << symbol causes error in a loop

Just another item. On occassion using EOF (i.e. end of file) sometimes conflicts with while read loops and etc..

If these weird instances occur I have just changed the marker from EOF to something else i.e <<-TIM
cat file|while read list
do
command <<-TIM
this
that
those
TIM
done