From 1ebd1313dc5a49fa4e56e65af818012614e40228 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 2 Mar 2014 11:04:53 -0800 Subject: [PATCH] Created SC2068 (markdown) --- SC2068.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC2068.md diff --git a/SC2068.md b/SC2068.md new file mode 100644 index 0000000..aa64b2b --- /dev/null +++ b/SC2068.md @@ -0,0 +1,25 @@ +## Add double quotes around ${@}, otherwise it's just like $* and breaks on spaces. + +### Problematic code: + + cp $@ ~/dir + +### Correct code: + + cp "$@" ~/dir + +### Rationale: + +Double quotes around `$@` prevents globbing and word splitting while still expanding to multiple separate arguments. + +Let's say you have three arguments: `baz`, `foo bar` and `*` + +`"$@"` will expand into exactly that: `baz`, `foo bar` and `*` + +`$@` will expand into multiple other arguments: `baz`, `foo`, `bar`, `file.txt` and `otherfile.jpg` + +Since the latter is rarely expected or desired, ShellCheck warns about it. + +### Contraindications + +None. \ No newline at end of file