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

Test expression with operator as a variable not parsed. #51

Open
Anvil opened this issue Dec 9, 2013 · 3 comments
Open

Test expression with operator as a variable not parsed. #51

Anvil opened this issue Dec 9, 2013 · 3 comments

Comments

@Anvil
Copy link

Anvil commented Dec 9, 2013

Hello

It looks like this expression is not parsed correctly.

[ -"${option_type:0:1}" "$value" ]
^-- Couldn't parse this test expression.
^-- Unexpected """. Fix any mentioned problems and try again.

For the record, the line context is available at https://github.com/Anvil/bash-argsparse/blob/master/argsparse.sh#L614

Thank you.

gerow pushed a commit to gerow/shellcheck that referenced this issue Jul 29, 2017
Fix broken headings in Markdown files
@ngzhian
Copy link
Contributor

ngzhian commented May 13, 2018

@koalaman i have possible fix for simple cases of this:
[ -"$op" "$file" ] parses, but triggers SC2058: Unknown unary operator
We can probably change SC2058 to check for this case too, what do you think?

@koalaman
Copy link
Owner

I think the best thing for this case would be to keep parsing the same, but to allow continuing on failure. That way you can do whichever dynamic magic you want, and if ShellCheck doesn't get it, you can just disable it.

I don't think that fixing the case of -"$op" by itself is sufficiently useful if op='-n'; [ "$op" foo ] doesn't work.

@paride
Copy link

paride commented Jul 13, 2020

It seems that using test <expr> instead of the equivalent [ <expr> ] allows shellcheck to correctly parse the command.

paride added a commit to paride/cloud-utils that referenced this issue Jul 13, 2020
SC1087: Use braces when expanding arrays, e.g. ${array[idx]}
        (or ${var}[.. to quiet).

SC1073: Couldn't parse this test expression. Fix to allow more checks
See: koalaman/shellcheck#51
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

4 participants