1
sqlplus system/root @orcl<<END
SET SERVEROUTPUT ON
VAR RET NUMBER
EXEC :RET := 1
EXEC :RET := ${CREATE_FUNCTION}('${WKDir}','${WKFile}', ${DAYS})
EXIT :RET
END
Rtn=$?
echo The value is $Rtn
    if[[ ${Rtn} != 0 ]] then
        echo "Error"
        exit 1
    fi
echo "RRRRRRRRRRRRRRRRR"

#########################################################################
# PL/SQL コ・・ツケヤ
#########################################################################
sqlplus system/root @orcl<<END
SET SERVEROUTPUT ON
VAR RET NUMBER
EXEC :RET := 1
EXEC :RET := ${DELETE_FUNCTION}('${WKDir}','${WKFile}', ${COMMIT_CNT})
EXIT :RET
END

In the above code the value of Rtn is 0. But it is getting inside the if condition and printing "Error". Where as I need to continue with the pl/Sql code.

nkr
  • 3,026
  • 7
  • 31
  • 39

2 Answers2

0

Amend your script as below and it should work.

Rtn=$?
echo The value is $Rtn
    if [ ${Rtn} != 0 ]; then
        echo "Error"
        exit 1
    fi
echo "RRRRRRRRRRRRRRRRR"
Srini V
  • 11,045
  • 14
  • 66
  • 89
0

By default a shell script doesn't terminate on error, it just prints an error message to stderr and continues to execute subsequent commands. (This behaviour can be changed by set -e at the beginning of your script).

In your case (as already mentioned in comments) if[[ isn't correct syntax for if (the space is missing), the shell interprets it as a name of a command, there is no command with this name in your system, so the shell throws an error like that:

./test.sh: line 6: if[[ 0 != 0 ]]: command not found

...and continues to execute the next two commands:

echo "Error"
exit 1

Just for the sake of curiosity, you can create an executable file named if[[ (it could be just an echo hello world) and place it somewhere in the PATH. Your script will execute it.

Yoory N.
  • 4,881
  • 4
  • 23
  • 28