printf

Formatted output with precise control over text, numbers, and layout.

What it does

printf prints formatted output using format strings. It is more predictable than echo and preferred in scripts.

Quick Start

printf "Hello\n"
printf "%s %d\n" name 42

Examples

# Columns
printf "%-10s %5d\n" item 10

# Floating point
printf "%.2f\n" 3.14159

# Hex
printf "%x\n" 255

Notes