Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 of 4 tasks
e-kwsm opened this issue Mar 24, 2025 · 1 comment
Open
3 of 4 tasks

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

e-kwsm opened this issue Mar 24, 2025 · 1 comment

Comments

@e-kwsm
Copy link

e-kwsm commented Mar 24, 2025

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 ]
@e-kwsm
Copy link
Author

e-kwsm commented Mar 25, 2025

set -B
[ ! -o braceexpand ]
echo $?  # bash: 0, ksh: 1
[[ ! -o braceexpand ]]
echo $?  # bash: 1, ksh: 1

# shellcheck should suggest
! [ -o braceexpand ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant