Skip to content

No warning is issued against [ ! -a p ] and test ! -a p #3174

@e-kwsm

Description

@e-kwsm

For bugs

  • Rule Id (if any, e.g. SC1000): SC2166?
  • My shellcheck version (shellcheck --version or 'online'): online
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit
  • It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue

For new checks and feature suggestions

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

#!/bin/bash
# or
#!/bin/ksh
[ ! -a /bin/sh ]
echo $?

Here's what shellcheck currently says:

nothing

Here's what I wanted or expected to see:

A warning is issued against [ ! -a p ] since it is not well-defined.
Actually, bash 5.2.37 and ksh 2020.0.0 give different results: 0 and 1, respectively. It seems that bash performs

[ ! ] && [ /bin/sh ]
# or
[ -n '!' ] && [ -n /bin/sh ]

whereas ksh does

! [ -a /bin/sh ]
# or
! [ -e /bin/sh ]

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