help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printf '%s\n' "$@" versus <<< redirection


From: alex xmb ratchev
Subject: Re: printf '%s\n' "$@" versus <<< redirection
Date: Sat, 18 Feb 2023 17:02:22 +0100

On Sat, Feb 18, 2023, 4:18 PM Greg Wooledge <greg@wooledge.org> wrote:

> On Sat, Feb 18, 2023 at 10:46:08AM +0000, goncholden wrote:
> > My intention is to use prinf line by line on arguments containing
> newlines.  With a newline also introduced between arguments $1 $2 $3 etc.
>
> This is quite unique.  I don't believe I've ever seen someone try to
> write a command where each argument is a group of lines, and all of
> the groups of lines are supposed to be concatenated together to form
> one bigger group of lines.
>

i d try keep in a var array asignment , for speed
read , and stdin to tmp file , no good speed

cat nla ; printf \\n ; . nla ; nla $'1\n2\n3'
# newline args
 nla() {
unset -v r a
declare -a a r
declare IFS=$'\1'
a=( $* ) a=${a//$'\1'} IFS=$'\n' r=( $a )
declare -p r
 }
                                                              declare -a
r=([0]="1" [1]="2" [2]="3")


For this goal, printf '%s\n' "$@" seems to be the correct choice.
>
> The <<< "$@" construct is nonsensical.  Whatever it does (which is
> pretty hard to predict, since it doesn't have a real definition), it
> will not serve your goal.
>
> If you want to avoid a pipeline which would cause your processing loop
> to run in a subshell, then your syntax of choice would be:
>
> while read ...
> do
>     ...
> done < <(printf '%s\n' "$@")
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]