3 Replies Latest reply on Aug 14, 2020 11:47 AM by Gaz in Oz

    is _RC trustworthy?

    berx

      In SQLcl Version 20.2.0.174.1557
      on Oracle Linux Server release 8.2
      I want to utilize _RC variable to get the result (exit) code of the command executed with HOST.

       

      A simple test with ls in the shell shows the expected value:

       

      [oracle@localhost ~]$ ls /xxx
      ls: cannot access '/xxx': No such file or directory
      [oracle@localhost ~]$ echo $?
      2
      

       

      But when run in SQLcl the variable _RC is not updated:

       

      SQL> !ls /xxx
      ls: cannot access '/xxx': No such file or directory
      
      
      SQL> define
      
      
      
      
      DEFINE _DATE =  "05-AUG-20" (CHAR)
      DEFINE _CONNECT_IDENTIFIER =  "CDB$ROOT" (CHAR)
      DEFINE _USER =  "SYS" (CHAR)
      DEFINE _PRIVILEGE =  "AS SYSDBA" (CHAR)
      DEFINE _SQLPLUS_RELEASE =  "2002000000" (CHAR)
      DEFINE _EDITOR =  "vi" (CHAR)
      DEFINE _O_VERSION =  "Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
      Version 19.8.0.0.0" (CHAR)
      DEFINE _O_RELEASE =  "1908000000" (CHAR)
      DEFINE _PWD =  "/home/oracle" (CHAR)
      DEFINE _RC =  0 (NUMBER)
      

       

       

      interestingly, the way SQLcl executes commands is quite equipped to use the exit code:

       

      found with ps -ef | grep 70531:

      oracle     72108   70531  0 08:44 pts/0    00:00:00 bash -c SQLCLTERM=`stty -g 2>/dev/null` ; stty sane 2>/dev/null;  export PATH="/home/oracle:$PATH" && ps -ef | grep 70531; SQLCLEXIT=$? ; if test "M$SQLCLTERM" != "M" ; then stty "$SQLCLTERM" 2>/dev/null ; fi; exit $SQLCLEXIT
      
      

       

      you can see, it uses the variable SQLCLEXIT - but somewhere it's content get lost. ble

       

      Does anyone if/how I can get reliable results from HOST command into SQLcls variables?