I'm having this weird issue that I've been staring at for a few hours now and I can't seem to figure out whats wrong. I'm writing a dependency management system for a larger project and one of the front-end scripts, which actually does little more than just parsing CLI arguments and calling a library function with the correct options, consistently gets terminated by the OS with a SIGTERM signal (the ERR trap) seemingly due to an error that gets raised by or around the pipe to xargs, hence exiting with code 143.
The offending exerpt:
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit nullglob dotglob globstar
trap 'kill 0' ERR
(return 0 2>/dev/null) \
&& echo 'This script cannot be sourced' >&2 \
&& exit 1
# Built-in default options
declare -A ARGS_DEFAULTS+=(
[MODULES]=
[PATHNAMES]=
[DEPENDENCIES]=
[REVERSE]=
)
# ------------------------------------------------------
# Variable setup and argument parsing goes here, omitted
# for brevity. Assume all variables have correct values
# (tested). All arguments are ultimately saved in the
# `ARGS` associative array. Options from boolean CLI
# arguments (e.g. `ARGS[PATHNAMES]`) will hold `1` if
# set, `0` or `null` otherwise, depending on whether or
# not it has a user-defined default value.
# ------------------------------------------------------
if (( ${ARGS[DEPENDENCIES]:-0} ))
then if (( ${ARGS[REVERSE]:-0} ))
then @module:dependents "$MODS_DIR/" "${ARGS[MODULES]}"
else @module:dependencies "$MODS_DIR/" "${ARGS[MODULES]}"
fi
else @module:resolve "$MODS_DIR/" "${ARGS[MODULES]}"
# Replacing `xargs` with other commands — e.g. `head` or
# `tail` — results in the same error.
fi | xargs -I{} echo ${ARGS[PATHNAMES]:+"$MODS_DIR/"}'{}'
The script outputs the correct information, but gets terminated upon reaching the pipe to xargs. Of course, I can write the exact same in the terminal and it works just fine, even with the pipefail option set. The xargs command doesn't seem related (at least not directly). For instance, if substituted with any other command (head or tail, for example), the same problem happens. Both ARGS and MODS_DIR variables are defined, as would any one of them not be correctly defined and initialized, execution of the script would result in no valid output at all.
Any ideas?
kill 0does?