Skip to content

printf-variable-format

Shellsuspiciousno fixdefault: offshell/shellcheck

Reports a printf whose format string contains an expansion and no %.

The value is the format, so a % or a backslash in it is read as an instruction, and the output is wrong or an error (a file name with %s in it). The data belongs in an argument.

To fix, write printf '%s\n' "$var".

Reported
...
read -r line
read -p "x" -r line
printf "$fmt"
printf "%s $x\n" y
printf "a$x" y
printf '%s' "$x" "a $b"
printf 'literal $x'
...
shell:
lint:
rules:
printf-variable-format: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line printf-variable-format in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
shellcheck SC2059 partial Does not know which variables hold only safe text.