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
It turns out that with a bit of trickery there is a way, although I haven't fully managed to suppress the interpreted commands but pretty close to what I want.
Change test.jsh
to:
#!/usr/bin/env sh
tail -n +4 "$0" | jshell -s "$@"
exit $?
System.out.println("Hello World")
/exit
Which gives us:
⚡ ./test.jsh
-> System.out.println("Hello World")
Hello World
-> /exit