Files
java-devops-demo/jbang/scripts/jb.sh
T

24 lines
819 B
Bash
Executable File

#!/usr/bin/env bash
# Runs JBang. Uses a real `jbang` launcher on PATH if there is one; otherwise emulates the
# launcher around the jbang-cli fat jar from Maven Central.
#
# Why the emulation is needed: the jar does not run your script itself. It prints the final
# `java ...` command line on stdout and exits with status 255, and the `jbang` shell launcher
# evals that line. This script does the same.
#
# Environment noise ("Picked up JAVA_TOOL_OPTIONS ...") is stripped from stderr.
JBANG_JAR="${JBANG_JAR:-/tmp/jb/jbang-cli-0.132.1-all.jar}"
if command -v jbang >/dev/null 2>&1; then
exec jbang "$@"
fi
out=$(java -jar "$JBANG_JAR" "$@" 2> >(grep -v '^Picked up' >&2))
rc=$?
if [ "$rc" -eq 255 ]; then
eval "$out" 2> >(grep -v '^Picked up' >&2)
exit $?
fi
[ -n "$out" ] && printf '%s\n' "$out"
exit "$rc"