1

my code is always stopping after ENDOFSQL; How to resolve this Problem and print the last echo?

#!/bin/bash

sqlplus db/pass << ENDOFSQL

@script.sql

exit;   
ENDOFSQL;

echo -e "text"
1
  • code or something else ? Commented Mar 5, 2013 at 14:33

2 Answers 2

2

You must remove the semicolon ; at the end of ENDOFSQL;. Otherwise, your here document extends until the end of file and ENDOFSQL; and echo is part of the here document

#!/bin/bash

sqlplus db/pass << ENDOFSQL

@script.sql

exit;   
ENDOFSQL

echo -e "text"

See Here Documents for details

The format of here-documents is:

<<[-]word
        here-document
delimiter

This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command.

Sign up to request clarification or add additional context in comments.

1 Comment

It is working without the semicolon ; at the end of ENDOFSQL !!! Thanks all for help : )
0

Call it like this:

#!/bin/bash

sqlplus db/pass @script.sql
echo -e "text"

Make sure you have the exit at the end of your .sql file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.