feat(user/bkfeh):Process stdin and psargs separately
[BK-2020-03.git] / unitproc / bkt-read_psarg
diff --git a/unitproc/bkt-read_psarg b/unitproc/bkt-read_psarg
new file mode 100644 (file)
index 0000000..0e583eb
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+# Desc: Reads positional arguments
+
+yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
+die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
+must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
+read_psarg() {
+    # Desc: Reads arguments; outputs as stdout lines
+    # Input: args
+    # Output: stdout (newline delimited)
+    # Example: read_psarg "$@"
+    # Depends: GNU bash (version 5.1.16)
+    # Version: 0.0.1
+    local input_psarg output;
+    
+    # Store arguments
+    if [[ $# -gt 0 ]]; then
+        input_psarg="$*";
+    fi;
+    
+    # Store as output array elements
+    ## Read in positional arguments
+    if [[ -n $input_psarg ]]; then
+        for arg in "$@"; do
+            output+=("$arg");
+        done;
+    fi;
+
+    # Print to stdout
+    printf "%s\n" "${output[@]}";
+}; # read positional argument to stdout lines
+main() {
+    read_psarg "$@";
+};
+
+main "$@";