return code and sqlplus

Calling a shell script from within sqlplus is buggy…

I have reported bug 3798918 in (back in 2004) and bug 13349119 in because some metalink guru closed 3798918 as not reproducible.

As written in return code, host does not return the correct code

SQL> host exit 7
SQL> def _RC
DEFINE _RC             = "0" (CHAR)

If you never use _RC, you may believe you are safe. But watch this :

SQL> get list
  1  #!/bin/sh
  2  if /bin/false
  3  then
  4    echo this is wrong
  5* fi
SQL> host ./
this is wrong

The return code not being set is not only affecting the _RC variable, but it is also affecting all subshells !

Note this is not reproducable with SQLPLUS /NOLOG

SQL> host false
SQL> def _rc
DEFINE _RC             = "1" (CHAR)
SQL> conn x/x
ORA-01017: invalid username/password; logon denied
SQL> host false
SQL> def _rc
DEFINE _RC             = "0" (CHAR)

After my (failed or successfull) tentative to connect as x/x, it is reproducible again

3 Replies to “return code and sqlplus”

  1. I was a bit skeptical about the bug affecting subshells, so I tried it on AIX and I can’t get it to reproduce, either using ksh or bash.

    What platform are you on?

    Also, for on AIX I get the _RC bug regardless of /nolog.

  2. ok, I am glad you are sceptical 🙂

    I can reproduce it with on AIX 6 with /nolog and / as sysdba

    I can reproduce it with on AIX 6 with / as sysdba

    I do not have bash installed.

  3. with nolog, aix 6.1 ML 6, oracle 10gR2

    sqlplus /nolog
    SQL*Plus: Release - Production on Tue Dec 18 14:23:12 2012
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    SQL> ho /bin/false
    SQL> def _RC
    DEFINE _RC             = "0" (CHAR)
    SQL> ho oslevel -r

    with connection, same environment

    SQL> conn / as sysdba
    SQL> ho /bin/false || echo yes

    Any doubt ?

Leave a Reply

Your email address will not be published.