Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Syntax error in my script

Posted on 2013-05-10
7
476 Views
Last Modified: 2013-05-10
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

0
Comment
Question by:YZlat
7 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39156345
Sorry, I didn't see what you're really after.

I'll be back!
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 275 total points
ID: 39156429
Remove the () parenthesis:
. . . here:
export ORACLE_SID=DBNAme
ORAENV_ASK=NO
. . . .and here:
EOF |\
while read line
do . . .

Open in new window


PS: Notice the back-slash '\' after the pipe '|'
:p
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39156432
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.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39156511
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.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39156533
MikeOM_DBA, Thanks!

What does backslash there do? It actually worked without the backslash
0
 
LVL 29

Assisted Solution

by:serialband
serialband earned 25 total points
ID: 39156810
Backslash means continue to the next line as if the newline doesn't exist.  It's used for helping you format long lines into more easily readable paragraphs.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39156866
Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question