Skip to content
smichel17 edited this page Dec 30, 2020 · 5 revisions

This printf format string has no variables. Other arguments are ignored.

Problematic code:

place="world"
printf hello $place

Correct code:

place="world"
printf "hello %s\n" "$place"

Rationale:

ShellCheck has noticed that you're using a printf with multiple arguments, but where the first argument has no %s or equivalent variable placeholders.

echo accepts zero or more strings to write, e.g. echo hello world.

printf instead accepts one pattern/template with zero or more %s-style placeholders, and one argument for each placeholder.

Rewrite your command using the right semantics, otherwise all arguments after the first one will be ignored:

$ printf hello world\\n
hello

$ printf "hello world\n"
hello world

$ printf "hello %s\n" "world"
hello world

Exceptions:

If you wanted a no-op, use : instead.

: ${place=world}

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally