Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Printf builtin missing v flag support

2015-12-31 07:16:00 +0000, Starms, William Albert (MU-Student):
> I had a script malfunctioning on me and printing “-v” to
> stdout, and I found that it’s because zsh (version 5.2)
> doesn’t seem to support the v flag that bash has. I did some
> digging through GNU's bash source and it seems to have been
> added somewhere between 3.0 and 3.1. According to the bash
> documentation:
> printf: printf [-v var] format [arguments]

Yes, that's a bash-specific feature.

See also ksh93 where:

var=$(printf format arg)

doesn't involve a fork nor pipe (but still trims the trailing
newline characters)

ksh93 tries to only fork to execute external commands. For
builtins when used in command substitutions, ksh93 just adds
their output to the substituted value without actually going
through the whole actual printing through a pipe and reading at
the other end.

That avoids having to add a -v for every builtin command.

$(...) still creates a subshell environment though.


Messages sorted by: Reverse Date, Date, Thread, Author