Skip to content

Suggest -z/-n for comparison against empty string (= ''/!= '') #3187

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

Open
2 of 4 tasks
e-kwsm opened this issue Apr 14, 2025 · 0 comments
Open
2 of 4 tasks

Suggest -z/-n for comparison against empty string (= ''/!= '') #3187

e-kwsm opened this issue Apr 14, 2025 · 0 comments

Comments

@e-kwsm
Copy link
Contributor

e-kwsm commented Apr 14, 2025

For bugs

  • Rule Id (if any, e.g. SC1000): SC2244?
  • 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/sh
# shellcheck enable=avoid-nullary-conditions
[ "$1" = '' ]
[ "$1" != '' ]

Here's what shellcheck currently says:

Nothing.

Here's what I wanted or expected to see:


In - line 3:
[ "$1" = '' ]
  ^-------^ SCXXXX (style): Prefer -z to check empty string

Did you mean:
[ -z "$1" ]


In - line 4:
[ "$1" != '' ]
  ^--------^ SCXXXX (style): Prefer -n to check non-empty string

Did you mean:
[ -n "$1" ]

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