From eac6ec274b48c4f668d132bb674b1694db1a2ec6 Mon Sep 17 00:00:00 2001 From: koalaman Date: Tue, 6 Sep 2016 21:16:42 -0700 Subject: [PATCH] Created SC2182 (markdown) --- SC2182.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 SC2182.md diff --git a/SC2182.md b/SC2182.md new file mode 100644 index 0000000..95f000c --- /dev/null +++ b/SC2182.md @@ -0,0 +1,37 @@ +## This printf format string has no variables. Other arguments are ignored. + +### Problematic code: + +```sh +place="world" +printf hello $place +``` + +### Correct code: + +```sh +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: + +None. \ No newline at end of file