Skip to content

Shellcheck doesn't recognize [ as a regular command. #464

@Artoria2e5

Description

@Artoria2e5

Although the misuse of && in [ expr ] is common, it's still important to treat [ as a command, and the check for && / || should only happen when the last argument of the last command in the term appears to be ] (technically both quoted and un-quoted; but people that knows quoting also works since it is only an arg doesn't seem likely to make && mistakes.)

The test content is the same as #463.

# [(){ local IFS=' '; echo -n "$*"; } # shellcheck hangs at this funcdef
# bash: disable the [ builtin
enable -d [; echo -e '#!/bin/bash\necho "$@"'>/tmp/[; chmod +x /tmp/[; PATH=/tmp
[ a && echo b # here we also see shellcheck recgonize && like a syntax keyword; another issue.

A quick review on POSIX.1 2013 Volume 3 Shell & Utilities shows that [ is only a special form of the test util, while [[ and ]] may be keywords.

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