X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/6d44d2ad506f4107fd410ef4be6f93b8c5a9dfbb..595c2cf96c6eb87f082de03a0fd21810d44f7d93:/unitproc/bkt-read_stdin_psarg?ds=sidebyside diff --git a/unitproc/bkt-read_stdin_psarg b/unitproc/bkt-read_stdin_psarg index 50f76a7..aad2927 100644 --- a/unitproc/bkt-read_stdin_psarg +++ b/unitproc/bkt-read_stdin_psarg @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Desc: Reads stdin and 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 @@ -10,19 +11,18 @@ read_stdin_psarg() { # Output: stdout (newline delimited) # Example: read_stdin_psarg "$@" # Depends: GNU bash (version 5.1.16) + # Version: 0.0.3 local input_stdin input_psarg output; # Store stdin if [[ -p /dev/stdin ]]; then input_stdin="$(cat -)"; fi; - yell "DEBUG:$(declare -p input_stdin)"; # Store arguments if [[ $# -gt 0 ]]; then - input_psarg="$@"; + input_psarg="$*"; fi; - yell "DEBUG:$(declare -p input_psarg)"; # Combine as output array elements ## Read in stdin @@ -37,12 +37,10 @@ read_stdin_psarg() { output+=("$arg"); done; fi; - yell "DEBUG:$(declare -p output)"; # Print to stdout printf "%s\n" "${output[@]}"; }; # read stdin and positional argument to stdout lines - main() { read_stdin_psarg "$@"; };