Skip to content

Instantly share code, notes, and snippets.

@mef
Last active December 1, 2021 21:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mef/67ca2285390db98270ffda1b215840e8 to your computer and use it in GitHub Desktop.
Save mef/67ca2285390db98270ffda1b215840e8 to your computer and use it in GitHub Desktop.
make Oracle sqlcl work in git bash (windows)

About

Notes about how to fix issues met when trying to run sqlcl from git bash on Windows

Environment

Running mintty v2.8.5 on a windows 10 machine.

$ uname -a
MINGW64_NT-10.0 my-machine-Id 2.10.0(0.325/5/3) 2018-04-23 03:21 x86_64 Msys

## Note: the command below will only work after the fix has been applied, actually
$ sql -v
SQLcl: Release 18.2.0.0 Production
## July 2018

Pre-requisites

add the path to sqlcl to $PATH

This is done by adding the following to env.sh (in C:\Program Files\Git\etc\profile.d)

## Add sqlcl to path
export PATH="/c/Program Files/sqlcl/bin:$PATH"

Problem

Following errors are displayed when running sql command in git bash:

$ sql
/c/Program Files/sqlcl/bin/sql: line 197: [: /c/Program: binary operator expected
Error: Could not find or load main class oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli

Fixes

Edit /c/Program Files/sqlcl/bin/sql:

  • Add a call to function checkCygwin right after the call to setupClasspath source
@@ -488,6 +489,7 @@ checkADE
 setupArgs
 setupSQLHome
 setupClasspath
+checkCygwin
 checkJavaLocation
  • edit function checkCygwin so that mintty is detected:
@@ -216,6 +216,7 @@ function checkCygwin {
        #
        cygwin=false
        case `uname` in
+               MINGW64*) cygwin=true;;
                CYGWIN*) cygwin=true;;
        esac
  • (nice to have): edit check to support space characters in file path ( only needed if sqlcl is nested under a directory containing space characters, like Program Files:
@@ -194,7 +194,7 @@ function setupClasspath {
        # directory under lib.  These will be loaded
        # at startup as well.
        #
-       if  [ -f $SQL_HOME/cobertura.ser ]
+       if  [ -f "$SQL_HOME/cobertura.ser" ]
        then

Benefits

  • All the good things of bash.
  • no crash when leaving (unlike powerShell, which crashes each time CTRL + C is pressed inside sql cli).

Limits

  • /NOLOG option is not supported
  • Passwords are not hidden, they are displayed in clear text.
  • broken layout when pressing on arrow-up key to retrieve last executed queries. query text starts to overlap with previously displayed contents
  • Ctrl+L does not clear the screen

Conclusion: barely usable at the moment

Todo

Report problems to Oracle support. Need a specific access for this, apparently...

@jgebal
Copy link

jgebal commented May 9, 2019

nolog works but you need to use //NOLOG

@symekutz
Copy link

run sql.exe not sql in the bash shell and it works for me...

@bamcgill
Copy link

Nice gist, @krisrice pointed it out to me. Added it to our list for our next release.
Some of the command line issues are due to jline2 which we hope to resolve with an upgrade to jline3 which is in the works too.

@foobarbaz-pl
Copy link

foobarbaz-pl commented Dec 7, 2020

To make it work with MSYS2 and Git For Windows SDK you have to add MSYS* condition to checkCygwin function:

  case `uname` in
    MINGW64*) cygwin=true;;
     CYGWIN*) cygwin=true;;
       MSYS*) cygwin=true;;
  esac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment