Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

Syntax error in my script

I keep getting this error in my script:

"0403-057 Syntax error at line 6 : `<' is not matched."

I have gotten it before and the problem was EOF statement not being at the very beginning of a line. Not sure what is it this time. here is my script:

#!/usr/bin/ksh

(export ORACLE_SID=DBNAme
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF
connect username/pwd
set lines 4000
set trimspool on
set feedback off
set pages 0

  SELECT fieldid, field1, field2 from my_view;
        exit;
EOF)|
while read line
do
        if [[ -n $line ]]
                then eval $line
                         printf "[%-10s]\t[%-25s]\t[%-15s]\n" "$fieldid" "$field1" "$field2"
        fi
done

exit 0

Open in new window

Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Sorry, I didn't see what you're really after.

I'll be back!
ASKER CERTIFIED SOLUTION
Avatar of MikeOM_DBA
MikeOM_DBA
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Generally, you can't place anything into the same line with the terminating EOF, except for a pipe..

You can process the output of preceeding commands along with the output of the "here" document using a pipe in the opening line (the one containing "<<EOF")

However, all processing must be done in one single line, because everything placed into subsequent lines would become part of the "here" document.

Example:

(export ORACLE_SID=DBNAme
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF ) | while read line; do ...; done
connect username/pwd
set lines 4000
set trimspool on
set feedback off
set pages 0

  SELECT fieldid, field1, field2 from my_view;
        exit;
EOF

Since the line containing "while .. do ... done" could become very long I'd suggest creating a function to process the output.
Like this:

#!/usr/bin/ksh

function output_fn {
while read line
do
        if [[ -n $line ]]
                then eval $line
                         printf "[%-10s]\t[%-25s]\t[%-15s]\n" "$fieldid" "$field1" "$field2"
        fi
done
}

( export ORACLE_SID=DBNAme
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF ) | output_fn
connect username/pwd
set lines 4000
set trimspool on
set feedback off
set pages 0

  SELECT fieldid, field1, field2 from my_view;
        exit;
EOF

exit 0

Open in new window

Please note that all this would only make sense if you indeed must process the output of the preceeding statement (". oraenv"). Otherwise MikeOM_DBA's solution is the one to use.
Avatar of YZlat

ASKER

MikeOM_DBA, Thanks!

What does backslash there do? It actually worked without the backslash
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

Thanks!