syntax error: unexpected end of file

Hi,
I am newbie to UNIX scripting. I am facing this error "syntax error: unexpected end of file" while executing the following script:

------

a=$1
if [ $a -eq 1 ]
 then
        sqlplus -s prospect_stg/prospect_stg@mdmpt <<END
        insert into bckup_marc_parameter_lookup select * from prospect.marc_parameter_lookup;
        commit;
        exit;
        END
elif [ $a -eq 2 ]
 then
        sqlplus -s prospect_stg/prospect_stg@mdmpt <<END
        delete bckup_marc_parameter_lookup;
        insert into bckup_marc_parameter_lookup select * from prospect.marc_parameter_lookup;
        commit;
        exit;
        END
 else
        echo"pass a valid parameter to shell"
        echo"1 for INSERT into bckup_marc_parameter_lookup"
        echo"2 for DELETE/INSERT into bckup_marc_parameter_lookup"
fi

--------------
Command used for executing is:
sh insert_bckup_lkp.sh 1
Kindly help me to solve this error.

Hi,

must be space between echo and ""

else
echo "pass a valid parameter to shell"
echo "1 for INSERT into bckup_marc_parameter_lookup"
echo "2 for DELETE/INSERT into bckup_marc_parameter_lookup"
fi
1 Like

Thank you for your reply.
i did that. But showing the same error at the same line.(line 24)

remove space before END

a=$1
if [ $a -eq 1 ]
 then
        sqlplus -s prospect_stg/prospect_stg@mdmpt <<END
        insert into bckup_marc_parameter_lookup select * from prospect.marc_parameter_lookup;
        commit;
        exit;
END
elif [ $a -eq 2 ]
 then
        sqlplus -s prospect_stg/prospect_stg@mdmpt <<END
        delete bckup_marc_parameter_lookup;
        insert into bckup_marc_parameter_lookup select * from prospect.marc_parameter_lookup;
        commit;
        exit;
END
 else
        echo "pass a valid parameter to shell"
        echo "1 for INSERT into bckup_marc_parameter_lookup"
        echo "2 for DELETE/INSERT into bckup_marc_parameter_lookup"
fi
1 Like

with line leading TABs:

        sqlplus -s prospect_stg/prospect_stg@mdmpt <<-END
                    prospect.marc_parameter_lookup;
                    commit;
                    exit;
                     END

or

        sqlplus -s prospect_stg/prospect_stg@mdmpt <<END
        insert into bckup_marc_parameter_lookup select * from prospect.marc_parameter_lookup;
        commit;
        exit;
END

from 'man ksh':

     << [-]word
           The shell input is read up to a line that is the  same
           as word, or to an EOF. No parameter substitution, com-
           mand substitution, or file  name  generation  is  per-
           formed  on  word.  The  resulting  document,  called a
           here-document, becomes  the  standard  input.  If  any
           character  of  word  is  quoted,  no interpretation is
           placed upon the characters of the document. Otherwise,
           parameter  and command substitution occur, \NEWLINE is
           ignored, and \ must be used to quote the characters \,
           $,  `,  and  the  first  character  of  word.  If - is
           appended to <<, then all  leading  tabs  are  stripped
           from word and from the document.
1 Like

Thank you. It would be useful for me if you could say the significance of placing that END in the begining.

[marcdev@dyl02019dat03 eipfeed]$ sh insert_bckup_lkp.sh
insert_bckup_lkp.sh: line 2: [: : integer expression expected
insert_bckup_lkp.sh: line 10: [: : integer expression expected
pass a valid parameter to shell
1 for INSERT into bckup_marc_parameter_lookup
2 for DELETE/INSERT into bckup_marc_parameter_lookup

[marcdev@dyl02019dat03 eipfeed]$ sh insert_bckup_lkp.sh 1
69 rows created.

Commit complete.

The string chosen to end the here document (in your case the string "END") must be an exact match. The leading spaces or tabs mean that it is not an exact match.