Marcelo Marques
Marcelo Marques

Reputation: 57

Where´s the Issue with the EOF line?

I´ve changed from SuSE to RHEL and trying to us same code, I´m geting some error related with identation, I believe. SuSE was using bash3 and RHEL it´s using bash4.

Error message:

-bash: test.sh: line 9: unexpected EOF while looking for matching `)'
-bash: test.sh: line 21: syntax error: unexpected end of file

When I change:

    EOF)

For this (remove the tab):

EOF)

works fine. I understand the issue, but I would like to understand why it´s working fine with SuSE and RHEL it´s not. The point is that change this in the code will take a really big time and work, so is there any way to workaround this with unix session, or some config?

#!/bin/bash
    result=$(sqlplus -S /nolog  << EOF
        WHENEVER SQLERROR EXIT SQL.SQLCODE;
        Connect $ORACLE_USER/$(sh /bin/encrypt.sh -d "$ORACLE_PASS")@${HOST}:${PORT}/${HOST}
        set heading off
        set line 1000
        $QUERY;
        EXIT;
        EOF)
    result=$(echo $result | tail --lines=1)
    echo $result
    return $result
}

Upvotes: 0

Views: 1678

Answers (1)

Bayou
Bayou

Reputation: 3441

If you want to indent the here-doc delimiter, you should change << to <<-. You must use tabs to indent your code, spaces do not work. Note that ) doesn't follow the EOF; that's because bash can't close the $() otherwise.

VAL=$(cat <<-EOF
        derp
        EOF
)
echo "$VAL"
exit 0

Upvotes: 3

Related Questions