help-bash
[Top][All Lists]
Advanced

[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 21:54:22 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Saturday, November 13th, 2021 at 9:39 PM, Alex fxmbsw7 Ratchev 
<fxmbsw7@gmail.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




> On Sat, Nov 13, 2021, 22:21 irenezerafa irenezerafa@protonmail.com wrote:
>
> > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> >
> > On Saturday, November 13th, 2021 at 5:35 PM, Dennis Williamson <
> >
> > dennistwilliamson@gmail.com> wrote:
> >
> > > On Sat, Nov 13, 2021 at 11:11 AM irenezerafa via help-bash@gnu.org
> > >
> > > wrote:
> > >
> > > > I would like to have an option on whether to print function arguments
> > > >
> > > > with
> > >
> > > > a newline or keep them on the same line.
> > > >
> > > > Currently I am using tho following, but is there a more straightforward
> > > >
> > > > way to do this?
> > > >
> > > > This starts printing from argument nl+1 onwards.
> > > >
> > > > case $nwline in
> > > >
> > > > 1.  printf '%s\n' "${@:nl+1}" ;;
> > > >
> > > >     *) printf '%s' "${@:nl+1}" ;;
> > > >
> > > >     esac
> >
> > > line_end=$'\n'
> > >
> > > printf '%s%s' foo "$line_end" # outputs "foo" followed by a newline
> >
> > > line_end=''
> > >
> > > printf '%s%s' foo "$line_end" # outputs "foo" without a newline
> >
> > > Other line endings could be assigned, for example ' ' (space), $'\r' or
> > >
> > > even $'\r\n'.
> >
> > Dennis, the problem I have is that I cannot use
> >
> > fs='\n'
> >
> > printf '%s%s' "${ctp}${@:1:nl}${rst}" "$fs"
> >
> > Everything remains on the same line. What can I do?



reply via email to

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