printf-variable-format
What it does
Section titled “What it does”Reports a printf whose format string contains an expansion and no %.
Why it matters
Section titled “Why it matters”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".
Example
Section titled “Example”...read -r lineread -p "x" -r lineprintf "$fmt"printf "%s $x\n" yprintf "a$x" yprintf '%s' "$x" "a $b"printf 'literal $x'...Configuration
Section titled “Configuration”shell: lint: rules: printf-variable-format: warn # off (default), warn, errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line printf-variable-format in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”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. |