5df787bc1fe29a5bcce34e92ed74deaf70ccebc2
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; outputs as stdout lines
9 # Input: stdin (consumes)
10 # Output: stdout (newline delimited)
12 # return 1 stdin not present
13 # Example: printf "foo\nbar\n" | read_stdin
14 # Depends: GNU bash (version 5.1.16), GNU Coreutils 8.32 (cat)
16 # Attrib: Steven Baltakatei Sandoval (2024-01-29). reboil.com
17 local input_stdin output
;
20 if [[ -p /dev
/stdin
]]; then
21 input_stdin
="$(cat -)" ||
{
22 echo "FATAL:Error reading stdin." 1>&2; return 1; };
27 # Store as output array elements
29 if [[ -n $input_stdin ]]; then
30 while read -r line
; do
32 done < <(printf "%s\n" "$input_stdin") ||
{
33 echo "FATAL:Error parsing stdin."; return 1; };
37 printf "%s\n" "${output[@]}";
40 }; # read stdin to stdout lines
42 yell
"WARNING:This is a Bash function definition for read_stdin.";