help-bash
[Top][All Lists]
Advanced

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

Re: Information about the format construct for printf


From: Greg Wooledge
Subject: Re: Information about the format construct for printf
Date: Thu, 23 Mar 2023 20:08:32 -0400

On Thu, Mar 23, 2023 at 07:32:51PM -0400, Lawrence Velázquez wrote:
> On Thu, Mar 23, 2023, at 7:25 PM, Lawrence Velázquez wrote:
> > On Thu, Mar 23, 2023, at 6:41 PM, uzibalqa wrote:
> >> I could not find any information about the format construct for printf.
> >>
> >> Particularly for the not so straightforward  %*s  and  %-*s
> >
> > Run "man 3 printf".
> 
> Pardon me, itchy "Send" finger.  printf(3) is the C function;
> I meant "man 1 printf".

All of the above, and more.

Bash's printf implements all of the POSIX printf(1) stuff, plus some
bash extensions.

POSIX printf(1) implements most of printf(3) plus a few POSIX extensions.

So, in order to understand how bash's printf works, you need to know
the printf(3) bottom layer, and the printf(1) middle layer, and the
bash-specific top layer, plus all of the undocumented goodies along
the way.

One of the first examples in the GNU printf(3) happens to be:

           printf("%*d", width, num);

This should be sufficient to demonstrate how %*d works, and by extension,
how %*s would work.  You can even construct simple tests to verify it:

unicorn:~$ printf '<%*s>\n' 20 'hello world'
<         hello world>

If that's not enough detail, then you can read the rest of the man pages.



reply via email to

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