1 Reply Latest reply on May 27, 2017 11:16 AM by Christian Stein

    Shebang support for JShell

    Christian Stein

      I'm playing with "jshell" as a build platform (see https://github.com/sormuras/bach) and would like to make scripts "auto-executable" via a shebang instruction. Similar to "jjs" as described here: https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/shell.html

      Instead of calling: "jshell build.jsh" it would be cool to just execute "build.jsh"


      At the current build jdk-9-ea+170 a script file passed to jshell leads to:


      jshell[.exe] build.jsh

      |  Error:

      |  illegal character: '#'

      |  #!/usr/bin/jshell

      |  ^

      |  Error:

      |  illegal start of expression

      |  #!/usr/bin/jshell

      |    ^


      Is there an easy way to ignore the first line of the script? May it start with the single line comment token "//" and still be interpreted by the [unix] shell as a shebang?

      The "jshell build.jsh" script prints the error message ... and continues with the remainder of the script.


      Edit: around line 1156 jdk9/dev/langtools: 0eedec5776e4 src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java would be perfect place to detect and ignore a "#!..." line.


      Link to source added