feat(unitproc/bkt-read_stdin): Add exit codes
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Mon, 29 Jan 2024 20:56:23 +0000 (20:56 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Mon, 29 Jan 2024 20:56:23 +0000 (20:56 +0000)
unitproc/bkt-read_stdin

index 31469b38b046b96c650e00f1c6ed60b4bbbee9a6..bf1873eb86c1a75acf085896feb571a6e6b19e7c 100644 (file)
@@ -7,15 +7,20 @@ must() { "$@" || die "cannot $*"; } # runs args as command, reports args if comm
 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
-    # 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.0
+    # Attrib: Steven Baltakatei Sandoval (2024-01-29). reboil.com
     local input_stdin output;
 
     # Store stdin
     if [[ -p /dev/stdin ]]; then
         input_stdin="$(cat -)";
+    else
+        return 1;
     fi; 
     
     # Store as output array elements
@@ -28,9 +33,8 @@ read_stdin() {
 
     # Print to stdout
     printf "%s\n" "${output[@]}";
+
+    return 0;
 }; # read stdin to stdout lines
-main() {
-    read_stdin "$@";
-};
 
-main "$@";
+yell "WARNING:This is a Bash function definition for read_stdin.";