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

Re: bash completion and spaces



On Mon, Apr 26, 2021 at 01:49:42PM +0200, Thomas Schmitt wrote:
> > $ string='  hi    there     '
> > [...]
> > $ printf '<%s> ' $string ; echo
> > <hi> <there>
> 
> As C programmer i am now tempted to scream.
> (This command should really not have the same name as printf(3).)

There are a few changes between printf(3) and printf(1), and a few
more bash extensions added to bash's builtin implementation.

The big change here is that if you supply more arguments than there
are format specifiers, printf(1) implicitly loops, and reuses the
format specifier as many times as needed to consume all of the extra
arguments.  This is incredibly handy when used correctly.

The biggest change for bash's builtin is the -v option, which lets
you store the formatted result in a variable.  This is better than
using a command substitution, because it doesn't fork, and because
it doesn't drop trailing newlines the way a command substitution does.

There are several smaller changes as well, but you can dive into those
on your own. :-)


Reply to: