Skip to content

Files

Latest commit

 

History

History
31 lines (18 loc) · 658 Bytes

SC2048.md

File metadata and controls

31 lines (18 loc) · 658 Bytes

Pattern: Missing use of "$@" to prevent whitespace problems

Issue: -

Description

$*, 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.

Example of incorrect code:

cp $* ~/dir

Example of correct code:

cp "$@" ~/dir

Further Reading