From ece915ca68581580ed0795dd88fa6dc5691cd048 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 2 Jul 2017 20:52:37 +0800 Subject: astro/casa-script: hack to make it work as shebang of CASA scripts --- astro/casa/casa-script | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'astro/casa/casa-script') diff --git a/astro/casa/casa-script b/astro/casa/casa-script index a1e8e6b..ecee175 100755 --- a/astro/casa/casa-script +++ b/astro/casa/casa-script @@ -22,11 +22,33 @@ # https://github.com/pkgw/pwpy - intfbin/casa-script # -if [ $# -eq 0 ] || [ "x$1" == "x-h" ]; then - echo "usage: $(basename $0) [ script args ... ]" +PROG="${0##*/}" + +if [ $# -eq 0 ] || [ "x$1" = "x-h" ]; then + echo "usage: ${PROG} [ script.py args ... ]" exit 1 fi script="$1" +script2="$2" shift + +# HACK: make this wrapper work as the *shebang* of CASA scripts +if [ ! -f "${script}" ] && [ -f "${script2}" ]; then + # This wrapper is called from the *shebang* of the CASA script + # NOTE: + # By self-testing, when this wrapper called from the *shebang*, + # `$0` is the absolute path to this wrapper, but `$1` is the + # first 3 lines (excluding the shebang line) of the calling CASA + # script, whose path is stored as `$2`. + echo "DEBUG: ${PROG} is called from shebang" >&2 + script="${script2}" + shift +fi + +echo "================= casa-script wrapper ================" +echo "script: ${script}" +echo "arguments: $@" +echo "======================================================" + casa --log2term --nologfile --nogui -c ${script} -- "$@" -- cgit v1.2.2