Skip to content
koalaman edited this page Mar 2, 2014 · 5 revisions

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.

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