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

shellcheck fails to parse tests when the comparator is a variable. #3002

Open
4 tasks done
derekschrock opened this issue Jun 16, 2024 · 0 comments
Open
4 tasks done

Comments

@derekschrock
Copy link

derekschrock commented Jun 16, 2024

For bugs

For new checks and feature suggestions

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

#!/bin/sh

v1=1
v2=2

gt=">"
[ "$v1" $gt "$v2" ] || echo no
[ "$v2" $gt "$v1" ] && echo yes

gt="-gt"
[ "$v1" $gt "$v2" ] || echo no
[ "$v2" $gt "$v1" ] && echo yes

Here's what shellcheck currently says:

In test.sh line 9:
[ "$v1" $gt "$v2" ] || echo no
^-- SC1073 (error): Couldn't parse this test expression. Fix to allow more checks.
^-- SC1072 (error): Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.

Here's what I wanted or expected to see:

shellcheck to be able to handle the test where test is a var.

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