utility

printf — external utility

GNU external printf formats arguments using a format string. Bash also provides a builtin with its own extensions such as -v; the external command cannot assign a shell variable in its parent. Use a constant format and quoted arguments, never external input as the format string. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): [100% done]; 100% done.

Formal Syntax & Structure

bash syntaxbash
/usr/bin/printf FORMAT [ARGUMENT]...

Parameters & Attributes

NameTypeDescription
FORMATstringTrusted formatting template.
ARGUMENTstringValues supplied to the template.

Return Value

exit status

Zero on successful operation; nonzero on errors.

Working Example

Example Snippetbash
value='100% done'/usr/bin/printf '[%s]\n' "$value"builtin printf -v result '%s' "$value"printf '%s\n' "$result"
Bash Reference