neechbear/blip

View on GitHub
tests/240_cmdarg_helpers.sh

Summary

Maintainability
Test Coverage

Double quote array expansions to avoid re-splitting elements.
Open

    for shortopt in ${CMDARG_OPTIONAL[@]:-} ${CMDARG_REQUIRED[@]:-}
Severity: Minor
Found in tests/240_cmdarg_helpers.sh by shellcheck

Double quote array expansions to avoid re-splitting elements.

Problematic code:

cp $@ ~/dir

Correct code:

cp "$@" ~/dir

Rationale:

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.

Exceptions

When you want globbing of individual elements.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Double quote array expansions to avoid re-splitting elements.
Open

    for shortopt in ${CMDARG_OPTIONAL[@]:-} ${CMDARG_REQUIRED[@]:-}
Severity: Minor
Found in tests/240_cmdarg_helpers.sh by shellcheck

Double quote array expansions to avoid re-splitting elements.

Problematic code:

cp $@ ~/dir

Correct code:

cp "$@" ~/dir

Rationale:

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.

Exceptions

When you want globbing of individual elements.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

There are no issues that match your filters.

Category
Status