Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
with jshell-wrapper you get runnable java scripts: it removes the heading shebang, adds an "/exit" for good measure, and passes the result to jshell
TMP=`mktemp`
tail -n +2 $@ >> $TMP
echo "/exit" >> $TMP
$JAVA_HOME/bin/jshell -q --execution local $TMP
rm $TMP
#put this file in /usr/local/bin/ or somewhere in your $PATH
federico@pawa:~$ JAVA_HOME=/opt/jvm/jdk1.9.0/ ./test.sh
Hello world!
1
2
3
4
5
6
7
8
9
#!/usr/bin/env jshell-wrapper
System.out.println("Hello world!");
IntStream.range(1, 10).forEach(System.out::println);
@rodrigoeggea

This comment has been minimized.

Copy link

@rodrigoeggea rodrigoeggea commented Mar 21, 2021

Great wrapper script, but I changed the following line so I dont need the environment variable:
$JAVA_HOME/bin/jshell -q --execution local $TMP
to:
/usr/bin/env jshell -q --execution local $TMP

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