Shellcheck: SC2046 - Quote this to prevent word splitting

Created on 11 Apr 2016  路  5Comments  路  Source: koalaman/shellcheck

image

I quoted and it still tells me i didn't

Most helpful comment

Doing it like srstevenson shows gives me something like:
2524: arguments must be process or job IDs

All 5 comments

Oh right. Thanks!

Doing it like srstevenson shows gives me something like:
2524: arguments must be process or job IDs

@erwinkramer In your particular case shellcheck gives a false positive.
Generally any command substitutions should be quoted, but here you actually _need a word splitting_. That's because kill command recognizes a list of PIDs, not a single string with space separated numbers.

Just remove quotes and disable the warning like this:

# shellcheck disable=SC2046
kill -9 $(jobs -p)

Remember that such command will also throw a syntax error if there are no background jobs in your shell session. I humbly suggest to redirect stderr to /dev/null: kill -9 $(jobs -p) 2>/dev/null.

Huh, the arrow is off by four. Something's wrong with the tab handling

Arrow now points to the right thing.

The right thing in this case would be to disable to warning, as in this case word splitting is harmless and desirable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathaniel112 picture nathaniel112  路  4Comments

erichelgeson picture erichelgeson  路  5Comments

helau picture helau  路  4Comments

bje- picture bje-  路  3Comments

quchen picture quchen  路  3Comments