Table of Contents

Bash - printf (Builtin command)

About

printf in Bash is a builtin command that writes the formatted arguments to the standard output under the control of the format.

Syntax

printf [-v var] format [arguments]
Bash

where

Format

In addition to the standard printf%281%29 formats, %b causes printf to expand backslash escape sequences in the corresponding argument (except that \c terminates output, backslashes in \', \“, and \? are not removed, and octal escapes beginning with \0 may contain up to four digits), and %q causes printf to output the corresponding argument in a format that can be reused as shell input.

The format is reused as necessary to consume all of the arguments. If the format requires more arguments than are supplied, the extra format specifications behave as if a zero value or null string, as appropriate, had been supplied. The return value is zero on success, non-zero on failure.

Example

var=$'hello Nico\nHello Nico!'
printf "$var\n"
Bash
hello Nico
Hello Nico!
Plain text

Documentation / Reference