projects
/
BK-2020-03.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
chore(user/bkmml):Cleanup comment
[BK-2020-03.git]
/
unitproc
/
bkt-read_stdin
diff --git
a/unitproc/bkt-read_stdin
b/unitproc/bkt-read_stdin
index 31469b38b046b96c650e00f1c6ed60b4bbbee9a6..5df787bc1fe29a5bcce34e92ed74deaf70ccebc2 100644
(file)
--- a/
unitproc/bkt-read_stdin
+++ b/
unitproc/bkt-read_stdin
@@
-7,15
+7,21
@@
must() { "$@" || die "cannot $*"; } # runs args as command, reports args if comm
read_stdin() {
# Desc: Consumes stdin; outputs as stdout lines
# Input: stdin (consumes)
read_stdin() {
# Desc: Consumes stdin; outputs as stdout lines
# Input: stdin (consumes)
- # Output: stdout (newline delimited)
+ # Output: stdout (newline delimited)
+ # return 0 stdin read
+ # return 1 stdin not present
# Example: printf "foo\nbar\n" | read_stdin
# Example: printf "foo\nbar\n" | read_stdin
- # Depends: GNU bash (version 5.1.16)
- # Version: 0.0.1
+ # Depends: GNU bash (version 5.1.16), GNU Coreutils 8.32 (cat)
+ # Version: 0.1.1
+ # Attrib: Steven Baltakatei Sandoval (2024-01-29). reboil.com
local input_stdin output;
# Store stdin
if [[ -p /dev/stdin ]]; then
local input_stdin output;
# Store stdin
if [[ -p /dev/stdin ]]; then
- input_stdin="$(cat -)";
+ input_stdin="$(cat -)" || {
+ echo "FATAL:Error reading stdin." 1>&2; return 1; };
+ else
+ return 1;
fi;
# Store as output array elements
fi;
# Store as output array elements
@@
-23,14
+29,14
@@
read_stdin() {
if [[ -n $input_stdin ]]; then
while read -r line; do
output+=("$line");
if [[ -n $input_stdin ]]; then
while read -r line; do
output+=("$line");
- done < <(printf "%s\n" "$input_stdin");
+ done < <(printf "%s\n" "$input_stdin") || {
+ echo "FATAL:Error parsing stdin."; return 1; };
fi;
# Print to stdout
printf "%s\n" "${output[@]}";
fi;
# Print to stdout
printf "%s\n" "${output[@]}";
+
+ return 0;
}; # read stdin to stdout lines
}; # read stdin to stdout lines
-main() {
- read_stdin "$@";
-};
-
main "$@
";
+
yell "WARNING:This is a Bash function definition for read_stdin.
";