Given that Java 9 is upon us and we can finally have a java REPL with jshell
I was hoping there was a way to add a shebang to a script and have jshell
interpret it.
I tried creating test.jsh
:
#!/usr/bin/env jshell -s
System.out.println("Hello World")
/exit
However that gives:
⚡ ./test.jsh
| Error:
| illegal character: '#'
| #!/usr/bin/env jshell -s
| ^
| Error:
| illegal start of expression
| #!/usr/bin/env jshell -s
| ^
Hello World
It turns out there is an enhancement request for this in OpenJDK https://bugs.openjdk.java.net/browse/JDK-8167440.
Is there any other way to do this?
#!
isn't standard POSIX anyway but surely as far as magic numbers go it would be the most widely adopted. – Deckhouse