Skip to content

Instantly share code, notes, and snippets.

@beders beders/nashorn-bash
Last active Dec 8, 2015

What would you like to do?
A bash script that is also a nashorn script.
#!/usr/bin/env bash
JJS=$(type -p $JDK_HOME/bin/jjs || type -p jjs)
if [ -z $JJS ]; then
echo "I can't find jjs. Please install JDK 8 or set JDK_HOME."; exit 1
JS=$(mktemp $(basename "$0").XXXXXX)
tail -n+12 "$0" > $JS
$JJS -scripting $JS -- "$@"
rm $JS
exit 0;
# write your JS here:
print('This is Nashorn!\nHello sweet arguments:' + $ARG);

This comment has been minimized.

Copy link
Owner Author

beders commented Oct 17, 2015

Starting point for command line tools based on Nashorn that find jjs and support regular arguments.
For example, copy above into a file runme, then chmod u+x runme, then ./runme 'hi there'
Compared to ./runme -- 'hi there'when using #!/usr/bin/env jjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.