From 3c4ab729107bade539671447eee2e0e6817641b3 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 2 Mar 2014 11:07:00 -0800 Subject: [PATCH] Created SC2048 (markdown) --- SC2048.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC2048.md diff --git a/SC2048.md b/SC2048.md new file mode 100644 index 0000000..e955c88 --- /dev/null +++ b/SC2048.md @@ -0,0 +1,25 @@ +## Use "$@" (with quotes) to prevent whitespace problems. + +### Problematic code: + + cp $* ~/dir + +### Correct code: + + cp "$@" ~/dir + +### Rationale: + +`$*`, unquoted, is subject to word splitting and globbing. + +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