From 88643da3d30a92b7e746858ff28f050dcf08f932 Mon Sep 17 00:00:00 2001 From: James Pannacciulli Date: Sat, 16 Sep 2017 09:28:49 -0700 Subject: simplify output function, remove superfluous 3rd party util usage --- pars.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pars.sh b/pars.sh index 91b1022..670a552 100644 --- a/pars.sh +++ b/pars.sh @@ -24,7 +24,8 @@ parssh () { local _parssh_origopts=$- set -m - local _parssh_outfun=_parssh.out + local _parssh_out_stdout=true + local _parssh_out_file=false local _parssh_prepend_host=true local _parssh_ssh=_parssh.ssh @@ -58,8 +59,9 @@ parssh () { echo "'${2}.{out,err}': unable to write / modify file" return 97 } - local _parssh_outprefix="$2" - local _parssh_outfun=_parssh.out_redirect + local _parssh_out_prefix="$2" + local _parssh_out_stdout=false + local _parssh_out_file=true shift ;; r|-rinput) @@ -84,8 +86,9 @@ parssh () { echo "'${2}.{out,err}': unable to write / modify file" return 96 } - local _parssh_outprefix="$2" - local _parssh_outfun=_parssh.out_copy + local _parssh_out_prefix="$2" + local _parssh_out_stdout=true + local _parssh_out_file=true shift ;; esac @@ -122,8 +125,8 @@ parssh () { done $_parssh_ssh "$@" 2> >(_parssh.host_prepend >&2) |\ _parssh.host_prepend & - done <&9 2> >($_parssh_outfun err >&2) - } | $_parssh_outfun out + done <&9 2> >(_parssh.out err >&2) + } | _parssh.out out wait @@ -146,17 +149,14 @@ _parssh.host_prepend () done _parssh.out () { - cat - -} - -_parssh.out_redirect () { local _parssh_out_stream="$1" - cat - > "${_parssh_outprefix}.${_parssh_out_stream}" -} -_parssh.out_copy () { - local _parssh_out_stream="$1" - tee "${_parssh_outprefix}.${_parssh_out_stream}" + while read -r; do + [[ "${_parssh_out_stdout}" == "true" ]] && \ + printf "%s\n" "$REPLY" + [[ "${_parssh_out_file}" == "true" ]] && \ + printf "%s\n" "$REPLY" >> "${_parssh_out_prefix}.${_parssh_out_stream}" + done } _parssh.usage () { -- cgit v1.2.3