Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Shebang support for JShell

Christian SteinMay 25 2017 — edited May 27 2017

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

This post has been answered by Christian Stein on May 27 2017
Jump to Answer
Comments
Post Details
Added on May 25 2017
1 comment
1,078 views