Skip to content

Special parameter $# should be quoted in case numbers in IFS #3351

@krushia

Description

@krushia

For bugs with existing features

Here's a snippet or screenshot that shows the problem:

#!/bin/sh
f() {
while test $# -gt 0
do
 shift
done
}

IFS=0
f a b c

This will cause test to error when $# is 0, as it becomes test '' -gt 0

Here's what shellcheck currently says:

Nothing

Here's what I wanted or expected to see:

while test $# -gt 0
           ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions