]>
zdv2.bktei.com Git - BK-2020-03.git/blob - unitproc/bkt-read_stdin
   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) 
  11     # Example: printf "foo\nbar\n" | read_stdin 
  12     # Depends: GNU bash (version 5.1.16) 
  14     local input_stdin output
; 
  17     if [[ -p /dev
/stdin 
]]; then 
  18         input_stdin
="$(cat -)"; 
  21     # Store as output array elements 
  23     if [[ -n $input_stdin ]]; then 
  24         while read -r line
; do 
  26         done < <(printf "%s\n" "$input_stdin"); 
  30     printf "%s\n" "${output[@]}"; 
  31 }; # read stdin to stdout lines