@@ -82,12 +82,12 @@ progVersion() {
8282# ###############################################################################
8383
8484quiet=false
85- eol=-n
86- declare -a args =()
85+ keep_eol=false
86+ declare -a target_command =()
8787while [ $# -gt 0 ]; do
8888 case " 1ドル " in
8989 -k | --keep-eol)
90- eol=
90+ keep_eol=true
9191 shift
9292 ;;
9393 -q | --quiet)
@@ -102,21 +102,21 @@ while [ $# -gt 0 ]; do
102102 ;;
103103 --)
104104 shift
105- args =(${args [@]: +" ${args [@]} " } " $@ " )
105+ target_command =(${target_command [@]: +" ${target_command [@]} " } " $@ " )
106106 break
107107 ;;
108108 -* )
109109 usage 2 " ${PROG} : unrecognized option '1ドル '"
110110 ;;
111111 * )
112112 # if not option, treat all follow args as command
113- args =(${args [@]: +" ${args [@]} " } " $@ " )
113+ target_command =(${target_command [@]: +" ${target_command [@]} " } " $@ " )
114114 break
115115 ;;
116116 esac
117117done
118118
119- readonly eol quiet args
119+ readonly keep_eol quiet target_command
120120
121121# ###############################################################################
122122# biz logic
@@ -139,8 +139,10 @@ copy() {
139139catThenCopy () {
140140 local content
141141 content=" $( cat) "
142- # shellcheck disable=SC2086
143- echo $eol " $content " | copy
142+ {
143+ printf %s " $content "
144+ $keep_eol && echo
145+ } | copy
144146}
145147
146148teeAndCopy () {
@@ -151,8 +153,8 @@ teeAndCopy() {
151153 fi
152154}
153155
154- if [ ${# args [@]} -eq 0 ]; then
156+ if [ ${# target_command [@]} -eq 0 ]; then
155157 teeAndCopy
156158else
157- " ${args [@]} " | teeAndCopy
159+ " ${target_command [@]} " | teeAndCopy
158160fi
0 commit comments