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: goncholden
Subject: Re: printf '%s\n' "$@" versus <<< redirection
Date: Sun, 19 Feb 2023 10:00:17 +0000

------- Original Message -------
On Sunday, February 19th, 2023 at 6:04 AM, Kerin Millar <kfm@plushkava.net> 
wrote:


> On Sat, 18 Feb 2023 18:45:00 +0100
> Mike Jonkmans bashbug@jonkmans.nl wrote:
> 
> > On Sat, Feb 18, 2023 at 12:52:05PM +0000, Kerin Millar wrote:
> > 
> > > ...
> > > The manual has this to say:-
> > > 
> > > "If IFS is unset, or its value is exactly <space><tab><newline>, the 
> > > default, then sequences of <space>, <tab>, and <newline> at the beginning 
> > > and end of the results of the previous expansions are ignored, and any 
> > > sequence of IFS characters not at the beginning or end serves to delimit 
> > > words."
> > 
> > If IFS is unset then it is slightly ambiguous as to what the IFS characters 
> > are,
> > in the last part of this sentence.
> 
> 
> I agree.
> 
> --
> Kerin Millar

Have done as follows for the purpose of readability

theone()
(
    for arg in "$@"
    do
        while IFS='\n' read -r vl
        do
            printf '## vl: %s ##\n' "$vl"
        done <<< "$arg"
    done
)

The user would has a number of multiline variables to the function.  Then I 
would process each line in each variable according to some rules.

var1="
First Argument
Another Line"

var2="
Second Argument
Another Line"

theone "$var1" "$var2"



reply via email to

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