Created SC2048 (markdown)

koalaman
2014-03-02 11:07:00 -08:00
parent 1ebd1313dc
commit 3c4ab72910

25
SC2048.md Normal file

@@ -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.