2 # Desc: Reads stdin and positional arguments
4 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
5 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
6 must
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
8 # Desc: Consumes stdin and reads arguments; outputs as stdout lines
9 # Input: stdin (consumes)
11 # Output: stdout (newline delimited)
12 # Example: read_stdin_psarg "$@"
13 # Depends: GNU bash (version 5.1.16)
15 local input_stdin input_psarg output
;
18 if [[ -p /dev
/stdin
]]; then
19 input_stdin
="$(cat -)";
23 if [[ $# -gt 0 ]]; then
27 # Combine as output array elements
29 if [[ -n $input_stdin ]]; then
30 while read -r line
; do
32 done < <(printf "%s\n" "$input_stdin");
34 ## Read in positional arguments
35 if [[ -n $input_psarg ]]; then
42 printf "%s\n" "${output[@]}";
43 }; # read stdin and positional argument to stdout lines
45 read_stdin_psarg
"$@";