Last active
December 8, 2015 13:34
-
-
Save beders/15467fb4952f295f1a54 to your computer and use it in GitHub Desktop.
A bash script that is also a nashorn script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
fi | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Starting point for command line tools based on Nashorn that find jjs and support regular arguments.
For example, copy above into a file
runme
, thenchmod u+x runme
, then./runme 'hi there'
Compared to
./runme -- 'hi there'
when using#!/usr/bin/env jjs