Skip to content

.tip

· one of the small things

printf, not echo, in scripts

Shells disagree about how echo treats -n, -e and backslashes, and echo "$var" mangles a variable that starts with a dash.

printf '%s\n' "$value"
printf 'name=%s count=%d\n' "$name" "$count"

printf behaves the same everywhere, and the format string keeps the data separate from the layout.

shell