Bash 5 reference · Shell Builtins and Syntax

printf (Bash builtin)

Print formatted text with format specifiers like %s, %d and %.2f; more portable and predictable than echo.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

printf FORMAT [ARGUMENT...]

Parameters

ParameterDescription
%s / %d / %f String, integer and floating-point placeholders.
%-10s Left-align in a 10-character field.
%.2f Two decimal places.
-v VAR Store the result in a variable instead of printing.

Examples

Aligned columns (the format repeats)
printf '%-6s %5s\n' item price
printf '%-6s %5.2f\n' mug 8.5 teapot 24

Output

item   price
mug     8.50
teapot 24.00

Run this on your computer — see “Get Started” for setup.

printf -v and echo -n
printf -v stamp '%04d-%02d-%02d' 2026 1 5
echo "$stamp"
echo -n 'no newline'; echo ' <- echo -n'

Output

2026-01-05
no newline <- echo -n

Run this on your computer — see “Get Started” for setup.

echo handles options and backslashes differently between shells; use printf in scripts when the output format matters.

Was this page helpful?