Skip to content

Files

Latest commit

 

History

History
35 lines (20 loc) · 823 Bytes

SC2068.md

File metadata and controls

35 lines (20 loc) · 823 Bytes

Pattern: Missing double quotes for array expansion

Issue: -

Description

Double quotes around $@ (and similarly, ${array[@]}) prevents globbing and word splitting of individual elements, 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.

Example of incorrect code:

cp $@ ~/dir

Example of correct code:

cp "$@" ~/dir

Exceptions

When you want globbing of individual elements.

Further Reading