Skip to content

Instantly share code, notes, and snippets.

@beders
Last active December 8, 2015 13:34
Show Gist options
  • Select an option

  • Save beders/15467fb4952f295f1a54 to your computer and use it in GitHub Desktop.

Select an option

Save beders/15467fb4952f295f1a54 to your computer and use it in GitHub Desktop.
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
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);
@beders

beders commented Oct 17, 2015

Copy link
Copy Markdown
Author

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