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

Suggest modern [[ instead of [ or test in Bash #2590

Closed
2 tasks done
l0b0 opened this issue Sep 25, 2022 · 1 comment
Closed
2 tasks done

Suggest modern [[ instead of [ or test in Bash #2590

l0b0 opened this issue Sep 25, 2022 · 1 comment

Comments

@l0b0
Copy link

l0b0 commented Sep 25, 2022

For new checks and feature suggestions

Update: https://www.shellcheck.net/wiki/SC2292 is similar (Does it apply to test as well? I'd assume so…), but is not enabled at https://www.shellcheck.net/. Do we need an "all rules enabled" version of that page linked from the issue template?

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

#!/usr/bin/env bash
[ -n "$foo" ]
test -n "$foo"

Here's what shellcheck currently says:

No issues detected!

Here's what I wanted or expected to see:

Use "[[" instead of "["
Use "[[" instead of "test"

Rationale: [[ is generally safer and saner than [/test. See for example [[ Is a Builtin, But [[ Is Part of the Language and What is the difference between test, [ and [[?.

@brother
Copy link
Collaborator

brother commented Sep 28, 2022

As mentioned in the linked wiki page (SC2292) this is an optional check and must be activated explicit, shellcheck.net is operating in a "default mode".
Suggestions for changes to shellcheck.net is better discussed at that issue board - for instance adding a checkbox or something for "enable all optinal rules" or something.

shellcheck -o require-double-brackets myscript.sh

name:    require-double-brackets
desc:    Require [[ and warn about [ in Bash/Ksh
example: [ -e /etc/issue ]
fix:     [[ -e /etc/issue ]]

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

2 participants