[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Printing with and without newlines
From: |
irenezerafa |
Subject: |
Printing with and without newlines |
Date: |
Sat, 13 Nov 2021 22:27:14 +0000 |
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, November 13th, 2021 at 10:09 PM, irenezerafa
<irenezerafa@protonmail.com> wrote:
> > > nl=$'\n'
>
> > > notice the $
> >
> > Thanks. Have done as follows
> >
> > nl=3
> >
> > printf '%s\n' "nwline: $nwline"
> >
> > (( nwline == 1 )) && fs=$'\n' || fs=$' '
> >
> > printf '%s%s' "${ctp}${@:1:nl}${rst}" "$fs"
>
> > But still the first three arguments get displayed on a single line
>
> > pfm "Mary" "had" "a" "little" "lamb"
> >
> > nwline: 1
> >
> > Maryhada
>
> To continue, I tried declaring an array and changing IFS in a subshell
>
> nwline=1 ; aggr=("$@")
> (( nwline == 1 )) && fsb='\n' || fsb=' '
> ( IFS=$fsb ; echo "${aggr[*]}" )
>
> But the above still wrote on the same line
Then I remembered what you said and changed to
nwline=1 ; aggr=("$@")
(( nwline == 1 )) && fsb=$'\n' || fsb=' '
( IFS=$fsb ; echo "${aggr[*]}" )
This worked great and things are printed with newlines.
Still, with printf '%s%s' "$@" "$fs", I do not get the same result
nwline=1 ; aggr=("$@")
(( nwline == 1 )) && fs=$'\n' || fs=' '
( IFS=$fs ; echo "${aggr[*]}" )
printf '%s%s' "$*" "$fs"
Result:
pfm "Mary" "had" "a" "little" "lamb"
nwline: 1
Mary
had
a
little
lamb
Maryhadalittlelamb
Using ( IFS=$fs ; echo "${aggr[@]}" ) does not produce newlines though.
- Re: Printing with and without newlines, (continued)