Help us shape the future of Go! Take the 2026 Go Developer Survey

printf

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package printf implements the `printf` built-in (/ §10.18 details).

The implementation handles the bash extensions Go's fmt does not:

  • %b argument with backslash escapes interpreted (like echo -e)
  • %q argument shell-quoted (single-quoted with escapes for ')
  • %(FMT)T strftime-style timestamp; arg = epoch seconds, -1 = now, -2 = shell start

And the standard conversions %d, %i, %o, %u, %x, %X, %c, %s, %f, %e, %E, %g, %G, %%, with the usual flag/width/precision syntax. Bash format-reuse over extra args is implemented by cycling the format string until all args are consumed (printf "%s\n" a b c emits three lines).

mvdan/sh has its own printf builtin handled before our ExecHandler, so a bare `printf` invocation in a script never reaches us. This built-in serves `/bin/printf`, `command printf`, and direct dispatch via the registry for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() command.Command

New returns the printf command.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL